Commit Graph

294 Commits

Author SHA1 Message Date
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Allan Shortlidge
ce97377218 IRGen: Exclude unavailable enum cases from runtime layout calculations.
When `-unavailable-decl-optimization=complete` is specified, exclude
unavailable enum cases from the runtime layout of enums with payloads. Without
this, the type metadata for unavailable types may be referenced by enum cases
with unavailable payloads and cause linker failures.

Resolves rdar://107483852
2023-05-22 21:49:41 -07:00
Slava Pestov
0d1e50705e IRGen: Clean up some crusty old code 2023-04-20 22:05:46 -04:00
Slava Pestov
fa28d14518 IRGen: Small fix for opaque return types with variadic types 2023-04-13 11:48:02 -04:00
Slava Pestov
cca91797ed IRGen: Hollow out NecessaryBindings
This removes the "optimization" where a function type, metatype or
tuple type was split up into structural components, because it seems
that in general we need this structural type metadata again.

Similarly, this no longer tries to split up dependent concrete
conformances and instead passes the witness table in the context.

This makes the context larger potentially, but it avoids calls to
metadata access functions and swift_getWitnessTable() every time the
closure is invoked.
2023-03-28 19:21:45 -04:00
Slava Pestov
5e69db0d52 IRGen: Start plumbing shapes through NecessaryBindings 2023-03-28 19:21:45 -04:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Joe Groff
730c5cf632 Merge pull request #64295 from jckarter/noncopyable-hide-field-types
Don't let reflection handle noncopyable types yet.
2023-03-13 17:01:25 -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
ce9013a3f6 Fix IRGen to not use outlining for types with any kind of local archetype.
Previously it was testing for opened existentials specifically.

We should really teach outlining to handle local archetypes properly.
We'd have to build a generic signature for the lowered type, and that
probably means also adding requirements that are relevant to value
operations, but it would mean outlining would benefit all types, and
it would let us avoid bundling in unnecessary information from the
enclosing generic environment.

A minor side-effect of this is that we no longer bind names to
opened element type values.  The names were things like \tau_1_0,
which is not very useful, especially in LLVM IR where \tau is
printed with two UTF-8 escapes.
2023-03-10 19:00:28 -05:00
John McCall
0e932329c3 Fix fulfillments for type metadata and witness table packs
A lot of the fixes here are adjustments to compensate in the
fulfillment and metadata-path subsystems for the recent pack
substitutions representation change.  I think these adjustments
really make the case for why the change was the right one to make:
the code was clearly not considering the possibility of packs
in these positions, and the need to handle packs makes everything
work out much more cleanly.

There's still some work that needs to happen around type packs;
in particular, we're not caching them or fulfilling them as a
whole, and we do have the setup to do that properly now.
2023-03-10 12:52:37 -05:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05:00
Slava Pestov
212c9ba04d IRGen: Tweak mapTypeOutOfContext() usage 2022-11-02 11:43:53 -04: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
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
swift-ci
71c6bd422e Merge remote-tracking branch 'origin/main' into rebranch 2022-08-09 13:14:18 -07:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
swift-ci
16a8ce5251 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-01 12:13:40 -07:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00
swift-ci
536b393da9 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-28 18:33:20 -07:00
Holly Borla
574f01ab19 [IRGen] Use existential AnyObject throughout IRGen. 2022-06-28 13:21:03 -07:00
swift-ci
a12ece4179 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-24 20:54:07 -07:00
Holly Borla
429488f6c9 [Sema] Use ExistentialType for Any and AnyObject. 2022-06-17 18:29:15 -07:00
swift-ci
55000f53be Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 10:15:14 -07:00
zoecarver
f972f664d3 [cxx-interop] Runtime support for foreign reference types. 2022-06-14 12:18:05 -07:00
Ben Barham
b521dc7c42 [next] Handle new ObjectFormatTypes
LLVM has added two new object format types, add them as unhandled for
now.
2022-05-05 16:25:10 -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
Zoe Carver
786d6ed53d Merge pull request #42427 from zoecarver/ufo-metadata 2022-04-18 17:16:07 -07:00
zoecarver
491f556b77 [cxx-interop] Add basic support for using UFOs as members, etc.
This does not add support for using UFOs in generic contexts, this just emits their struct/field metadata as opaque pointers.
2022-04-18 14:47:02 -07:00
John McCall
6385934d7e Metadata emission for extended existential type shapes 2022-04-12 14:52:47 -04:00
Yuta Saito
43a25e89b7 [Wasm][IRGen] Add initial support for absolute function pointer
On some Harvard architectures like WebAssembly that allow sliding code
and data address space offsets independently, it's impossible to make
direct relative reference to code from data because the relative offset
between them is not representable.
Use absolute function references instead of relative ones on such targets.
2022-03-30 08:12:23 +00:00
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -08:00
Kuba (Brecka) Mracek
5f3489dacc Stop marking reflection metadata sections as 'no_dead_strip' on Darwin (#41224) 2022-02-07 13:06:32 -08:00
Kuba (Brecka) Mracek
ee7e04822c Add a -reflection-metadata-for-debugger-only flag that emits reflection metadata but does not link them from runtime data structures (#40853) 2022-02-03 05:53:31 -08:00
Doug Gregor
209167ae30 Eliminate spurious uses of ArchetypeType::getRoot(). 2022-01-19 09:54:34 -08:00
Doug Gregor
8df65e706e Remove unnecessary uses of NestedArchetypeType.
`ArchetypeType` has all of the API we need for these cases, so use
that instead to isolate us from `NestedArchetypeType`, which we would
like to eliminate soon-ish.
2022-01-14 21:25:32 -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
Michael Gottesman
43f6a971b3 [gardening] Add "&" to eliminate warning. 2021-11-24 21:07:02 -08:00
Kuba (Brecka) Mracek
b3f7c8d8b1 Make VFE / WME / conditional records work even with ObjC interop and with reflection metadata, take #2 (#39878) 2021-10-24 07:20:38 -07:00
Kuba Mracek
0616293353 Revert "Make VFE / WME / conditional records work even with ObjC interop and with reflection metadata (#39808)"
This reverts commit a51dc7e358.
2021-10-22 09:38:39 -07:00
Kuba (Brecka) Mracek
a51dc7e358 Make VFE / WME / conditional records work even with ObjC interop and with reflection metadata (#39808) 2021-10-20 10:13:50 -07:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Doug Gregor
24c761b74a Cannot back-deploy mangled names including isolated parameters.
Isolated parameters were introduced with concurrency, so don't mangle
names including them in back-deployed code.
2021-10-03 08:14:26 -07:00
swift-ci
c51550f30e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-30 15:11:41 -07:00
Kavon Farvardin
6739834f31 [IRGen] correct the order of demangling compat checks
In general, we need to check the features of a type in order
of newest to oldest, when determining the runtime version
that supports demangling that type.
2021-09-29 11:00:39 -07:00
Kavon Farvardin
c2aa4c3632 [IRGen][backdeploy] fix infinite recursion in metadata queries
One of the places where we ask whether a type's metadata should
be obtained via its mangled name was missing the newer, more
robust checking for minimum deployment target.
2021-09-28 14:51:28 -07:00
swift-ci
a5097f912e Merge remote-tracking branch 'origin/main' into rebranch 2021-08-30 10:13:12 -07:00
Varun Gandhi
b519489dd0 [IRGen] Support back-deployment of concurrency-related function types.
Fixes rdar://76473697.
2021-08-27 13:31:06 -07:00