Commit Graph

93 Commits

Author SHA1 Message Date
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Meghana Gupta
10057523ec Delete lifetime dependence mangling
Mangling this information for future directions like component lifetimes
becomes complex and the current mangling scheme isn't scalable anyway.

Deleting this support for now.
2024-09-05 22:03:58 -07:00
Meghana Gupta
fecd2b452d Don't mangle lifetime dependencies in older runtimes 2024-07-10 14:48:34 -07:00
Doug Gregor
9604019c87 Drop typed throws from the mangling in closure and field reflection metadata
This follows what we just did for `@isolated(any)` function types.

Part of rdar://130858222.
2024-07-03 20:14:01 -07:00
John McCall
2c6e0efb9c Suppress @isolated(any) in reflective metadata strings on old targets
Fix another aspect of rdar://129861211
2024-07-02 18:12:20 -04: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
Pavel Yaskevich
5d243bd8a2 [IRGen] Move marker protocol stripping from mangleTypeSymbol to mangleTypeForFlatUniqueTypeRef
The original check introduced by https://github.com/apple/swift/pull/71855
is too broad. For concrete metadata we call the runtime demangler so
we need to strip off marker protocols when mangling that string and
`mangleTypeForReflection` already does that.
2024-06-04 21:58:59 -07:00
Doug Gregor
79b78acdf6 Use SuppressibleProtocolSet as InvertibleProtocolSet
Collapse the representations of "suppressible" and "invertible"
protocol sets. Only minor adjustments were required.
2024-03-29 11:31:48 -07:00
Doug Gregor
854d0875ba Enable @_preInverseGenerics to suppress mangled names in more places
Fixes rdar://124644596.
2024-03-14 23:07:27 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Doug Gregor
1cd7a56ea6 [Noncopyable] Many protocol members without the inverse requirements of the protocol itself
This eliminates the ABI impact of making `Self` or associated types in
a protocol `~Copyable`.
2024-03-12 17:06:12 -07:00
Doug Gregor
e1ee19ac5e [Noncopyable generics] Suppress inverse conformance mangling for more symbols
Don't mangle inverse conformances for symbols related to dispatch thunks,
protocol members, and other entities that are inexorably tied to the
primary definition of the type and must have stable names.

Extend the conditional suppression of inverse conformance mangling to
property descriptors and more conformance-related symbols.
2024-03-07 10:01:20 -08:00
Doug Gregor
ed745a5c07 Merge pull request #72142 from DougGregor/preinversegenerics-extensions
Allow @_preInverseGenerics on extensions
2024-03-07 10:00:40 -08:00
Doug Gregor
5ec97ae4d7 Revert "Don't mangle inverse protocols within reabstraction thunks" 2024-03-06 19:11:32 -08:00
Doug Gregor
3745b5a5e7 Allow @_preInverseGenerics on extensions 2024-03-06 17:42:50 -08:00
Doug Gregor
cab88d15f3 Don't mangle inverse protocols within reabstraction thunks 2024-03-06 14:40:11 -08:00
Doug Gregor
f269cb5fbe Disable mangling of inverses for generalized existential shape symbols 2024-03-06 13:41:49 -08:00
Kavon Farvardin
215bd3cab4 Mangling: handle inverse requirements 2024-03-05 14:19:00 -08:00
Arnold Schwaighofer
b0424759d7 Add support for objective c protocol symbolic references
Using symbolic references instead of a text based mangling avoids the
expensive type descriptor scan when objective c protocols are requested.

rdar://111536582
2023-10-05 13:11:32 -07:00
Dario Rexin
5cbf9f9641 [IRGen] Handle complex single payload enum cases (#66289)
* [IRGen] Handle complex single payload enum cases

rdar://110138498

Handles single payload enum cases with more complex bit patterns (e.g. >64 bits or scattered) by storing a relative pointer to a function that reads the tag.

* Use proper symbol for enum tag helper
2023-06-02 11:49:57 -07:00
Joe Groff
4d6d7657fa Don't let reflection handle noncopyable types yet.
We don't have any language or runtime support for noncopyable types as generic
or dynamic types yet, and existing reflection code almost certainly assumes it
can copy the values it's working with, and will trap or corrupt state if it does
so with noncopyable types. But a class can have noncopyable fields while the
type itself is copyable, and existing code assumes that it can use `Mirror` or
other reflection mechanisms to safely traverse the contents of an arbitrary
class.

Allow this sort of code to continue working, while still preparing for forward
compatibility with future runtimes that do support noncopyable generics, by
emitting the type references for fields using a function that probes the
address of a new symbol in the Swift runtime. The symbol will either be missing
or defined with an absolute address of zero in current or previous runtime
versions, but can be changed to a non-null address in the future.
2023-03-13 11:50:24 -07:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00
Robert Widmann
dde0d8f609 Generalize the Mangling of Constrained Existential Types
Upgrade the old mangling from a list of argument types to a
list of requiremnets. For now, only same-type requirements
may actually be mangled since those are all that are available
to the surface language.

Reconstruction of existential types now consists of demangling (a list of)
base protocol(s), decoding the constraints, and converting the same-type
constraints back into a list of arguments.

rdar://96088707
2022-06-30 15:32:37 -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
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: across

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: command

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: current

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: discrimination

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: entities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: except

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inserted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interfere

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intrinsic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: might

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: objective

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outlined

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: payload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rearchitecting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reverse

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewritable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: shareably

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: speedup

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: template

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: witness

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
John McCall
24616aed5c Mangling support for extended existential type shapes 2022-04-11 22:25:11 -04:00
John McCall
5519749ade [NFC] Collect protocol decls, not type, in ExistentialLayout
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
2022-04-11 22:15:16 -04:00
Pavel Yaskevich
1c582bfcc3 [IRGen] Manging: Add special entry points for underlying type/conformance strings 2022-03-30 15:23:04 -07:00
Holly Borla
6e6ca13268 [Type System] Use the constraint type of an existential type in
various places that expect ProtocolType or ProtocoolCompositionType.
2022-01-13 19:30:44 -08:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
Kuba (Brecka) Mracek
66bd5e6a39 Add ASTMangler.AllowStandardSubstitutions to allow using a stripped-down libswiftCore (#40009) 2021-11-15 15:40:35 -08:00
Doug Gregor
7d7ec9e7d5 Don't emit marker protocols into runtime type metadata.
Marker protocols don't exist at runtime, drop them when mangling a type
for the purposes of runtime type metadata or reflection. Fixes
rdar://82314404.
2021-10-15 17:53:30 -07:00
Kuba Mracek
d0e05003f5 For individual runtime records for types/protocols/conformances, add and use new mangling suffixes 2021-09-29 13:14:58 -07:00
Doug Gregor
7f2117690c Skip standard substitutions for _Concurrency types when back-deploying.
When back-deploying concurrency support, do not use the standard
substitutions for _Concurrency-defined types (such as `Task`) in type
metadata because older Swift runtimes will not be able to demangle
them. Instead, use the full mangled names so the runtime can still
demangle them appropriately.

Addresses rdar://82931890.
2021-09-09 13:23:19 -07:00
Slava Pestov
51231e46fc ASTMangler: Pass around generic signature explicitly and remove CurGenericSignature
This pattern was really error-prone. I've fixed multiple bugs related
to CurGenericSignature not being set correctly at the right time, and
found another latent bug by inspection while doing this cleanup.
2021-08-25 16:44:09 -04:00
Slava Pestov
46fbf8c123 IRGen: Consistently mangle 'associated type paths' without a generic signature
Mangling uses a generic signature is used to shorten member types
to just a name where the protocol is unambiguous.

Unfortunately, in the particular case of 'associated type paths',
the IRGen mangler did not consistently set the right signature.

Sometimes, it would use no signature, and other times it would use
the signature of the concrete conforming type, which is incorrect
because the member type is written relative to the root protocol's
generic signature, <Self : P>.

This was caught by some new assertions I'm adding to the rewrite
system.

Note that this changes the mangling of a few symbols, but none
are public in the ABI.
2021-07-07 23:25:58 -04:00
Doug Gregor
b57a73ab42 [Concurrency ABI] Add standard substitutions for _Concurrency types.
Introduce a second level of standard substitutions to the mangling,
all of the form `Sc<character>`, and use it to provide standard
substitutions for most of the _Concurrency types.

This is a precursor to rdar://78269642 and a good mangling-size
optimization in its own right.
2021-06-01 17:15:02 -07:00
Nate Chandler
3243def046 Revert "[IRGen] Mangling for async, non-constant partial_apply thunks."
This reverts commit efaaee3656.
2021-04-06 15:51:33 -07:00
Nate Chandler
efaaee3656 [IRGen] Mangling for async, non-constant partial_apply thunks.
The scheme uses 'Tw' followed by the index--the number of non-constant
async partial applies that have been thunked in the function.
2021-03-14 17:30:43 -07:00
Slava Pestov
fc74fb0735 IRGen: Set the mangler's generic signature correctly
Otherwise, we'll fall over if we try to mangle a retroactive conformance.

Fixes <rdar://problem/70483417>.
2021-03-05 21:31:24 -05:00
John McCall
945011d39f Handle default actors by special-casing layout in IRGen instead
of adding a property.

This better matches what the actual implementation expects,
and it avoids some possibilities of weird mismatches.  However,
it also requires special-case initialization, destruction, and
dynamic-layout support, none of which I've added yet.

In order to get NSObject default actor subclasses to use Swift
refcounting (and thus avoid the need for the default actor runtime
to generally use ObjC refcounting), I've had to introduce a
SwiftNativeNSObject which we substitute as the superclass when
inheriting directly from NSObject.  This is something we could
do in all NSObject subclasses; for now, I'm just doing it in
actors, although it's all actors and not just default actors.
We are not yet taking advantage of our special knowledge of this
class anywhere except the reference-counting code.

I went around in circles exploring a number of alternatives for
doing this; at one point I basically had a completely parallel
"ForImplementation" superclass query.  That proved to be a lot
of added complexity and created more problems than it solved.
We also don't *really* get any benefit from this subclassing
because there still wouldn't be a consistent superclass for all
actors.  So instead it's very ad-hoc.
2020-12-02 18:47:13 -05:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Azoy
4ff28f2b40 Implement Tuple Hashable Conformance 2020-10-22 18:28:02 -04:00
Azoy
fd950ebbf3 Implement Tuple Comparable Conformance
Add protocol witnesses for all Comparable requirements
2020-10-22 18:27:07 -04:00
Azoy
e60ef84bd2 Implement Tuple Equatable Conformance 2020-10-22 18:24:28 -04:00
Joe Groff
7d3a4b1c0c IRGen: Name the symbol for the private use area attached to protocol conformance descriptors.
Make it easier to track the memory usage of these symbols.
2020-07-14 10:02:43 -07:00
Joe Groff
ee08197010 Factor appendAnyProtocolConformance out of the conformance mangling.
We want to be able to use mangled names to refer to protocol conformances in addition to type
metadata. Provide an ASTMangler method that can render an arbitrary abstract or concrete
`ProtocolConformanceRef`, factoring it out of the code used to emit conditional conformance arguments
in `appendProtocolConformance`.
2020-03-20 15:06:42 -07:00
Joe Groff
fe1186447b IRGen: Generate runtime type manglings using ObjC runtime names.
In order for the runtime demangler to be able to find ObjC classes and protocols, it needs to
have the runtime name of the declaration be in the mangled name. Only do this for runtime manglings,
to minimize the potential ABI impact for symbol names that already have the source-level names of
ObjC entities baked in. Fixes SR-12169 | rdar://59306590.
2020-03-05 16:55:00 -08:00
Robert Widmann
3bd0044143 [Gardening] Remove remaining casting artifacts 2020-02-07 16:09:31 -08:00
Slava Pestov
7d8b40bbb9 IRGen: Fix warning about unused capture 2020-01-08 22:19:59 -05:00