Commit Graph

195 Commits

Author SHA1 Message Date
Dario Rexin
93a70a0e38 Merge pull request #67349 from drexin/wip-resilient-metadata-inst
[IRGen] Fix enum metadata instantiation for resilient payload
2023-07-18 13:11:36 -07:00
Dario Rexin
8a260ff089 [Test] Add tests for prespecialized single payload enums with layout strings 2023-07-18 09:43:39 -07:00
Dario Rexin
649aa1ad72 [Test] Add tests for prespecialized single payload enums with layout strings 2023-07-18 09:41:22 -07:00
Dario Rexin
c8537963fa [Test] Add tests for prespecialized singleton enums with layout strings 2023-07-18 09:12:47 -07:00
Dario Rexin
937d1727a3 [IRGen] Fix enum metadata instantiation for resilient payload
The metadata can't be constant when we generate a layout string at runtime.
2023-07-17 16:00:41 -07:00
Rintaro Ishizaki
ababa1e461 [Parse] Accept 'self' after 'each'
Also move 'repeat', 'each', and 'any' expression parsing to
'parseExprSequenceElement'

rdar://107450487
2023-07-10 15:37:00 -07:00
Dario Rexin
8ccaad1db5 [IRGen] Emit swift_singlePayloadEnumGeneric_destructiveInjectEnumTag
Assign swift_singlePayloadEnumGeneric_destructiveInjectEnumTag as witness function on generic single payload enums when using layout strings
2023-06-29 10:39:54 -07:00
Dario Rexin
3524945cd4 [IRGen+Runtime] Implement getEnumTag for singleton enums in layout strings (#66985) 2023-06-28 14:25:34 -07:00
Dario Rexin
ca664141cc [IRGen+Runtime] Add support for initializeBufferWithCopyOfBuffer to layout strings (#66965) 2023-06-27 18:05:30 -07:00
Dario Rexin
fc6834daf6 [IRGen+Runtime] Add getEnumTag for layout strings on simple single payload enums (#66941) 2023-06-26 19:32:51 -07:00
Dario Rexin
253d8fbf33 [IRGen+Runtime] Add getEnumTag for layout strings on generic single payload enum (#66911) 2023-06-23 20:43:28 -07:00
Dario Rexin
270089f297 [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset (#66899)
* [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset

getEnumTag impl for layout strings of fixed sized enums that use a function to fetch the enum tag

* Fix potential UB in IRGen
2023-06-23 18:10:55 -07:00
Dario Rexin
36ddb77fcd [IRGen+Runtime] Layout string getEnumTag for generic multi payload enums (#66872)
We already store all necessary information to extract the tag in the layout string, so we should utilize it for the getEnumTag witness
2023-06-22 19:07:50 -07:00
Dario Rexin
493a25faae [IRGen+Runtime] Add layout string support for generic single payload enums (#66791) 2023-06-20 20:46:54 -07:00
Dario Rexin
874b577280 [IRGen] Use EnumImplStrategy to generate getEnumTag function for layo… (#66707)
* [IRGen] Use EnumImplStrategy to generate getEnumTag function for layout strings

rdar://110794898

The implementation in TypeLayout seems to have a bug causing wrong tags to be returned on 32 bit systems.

* Don't use unsupported types in tests
2023-06-16 18:14:48 -07:00
Dario Rexin
d74c085fe8 [Runtime+IRGen] Add layout string support for generic singleton enums (#66647) 2023-06-14 20:13:15 -07:00
Michael Gottesman
b2a52ff036 [move-only] Do not attempt to lazily deserialize the moveonly deinit table in IRGen.
SIL Functions are serialized in canonical SIL before they have their final ABI
adjusted for large function arguments. Large function argument ABI is adjusted
to be indirect as part of the transition from canonical SIL to lowered SIL. This
means that if we deserialize a function from another module in canonical SIL and
attempt to call it in IRGen we will call it with the wrong ABI implying if we
reference any fields of the type in the deinit we will most likely crash (among
other potential issues).

This patch fixes the issue by changing IRGen to not lazily deserialize the
moveonly deinit table and its associated functions. Instead if we do not have
our table already deserialized, we just call the function's deinit via the
destroy value deinit table.

rdar://110496872
2023-06-09 15:41:38 -04: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
Dario Rexin
e6fe6befe7 [IRGen] Include extra tag bytes in offset in layout strings (#66259)
rdar://110088270

When extra tag bytes are used in single payload enums, the generated layout string does not include the tag bytes in its offset after the enum payload. This causes subsequent ref count operations to use the wrong memory location.
2023-05-31 20:54:47 -07:00
Dario Rexin
5db2b28420 [Runtime] Handle single payload enums in swift_resolve_resilientAccessors (#66218)
rdar://109803119

It is sufficient to skip the header, because everything after that are regular ref counts
2023-05-30 18:27:00 -07:00
Sophia Poirier
0594efc0ce Merge pull request #66214 from sophiapoirier/tuple-expansion-without-dot-element
[Variadic Generics] drop requirement of .element for tuple expansion
2023-05-30 16:29:55 -04:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Michael Gottesman
8579c1924d [move-only] Make sure that we serialize deinits and if we are not able to see the value witness function, call it via the value witness function.
Some notes:

1. I put in both a swiftpm like test case and a library evolution test case. I
also updated the moveonly_deinit serialization swift test to show that we
actually serialize the deinit.

2. I changed when we emit the deinit table to only be when we have a type with
an actual value type destructor. Notably this doesn't include classes today so
as a side-effect, we no longer attempt to devirtualize moveonly class deinits.
This doesn't affect anything we are trying to actually do since we do not
support noncopyable classes today. With that in mind, I changed one test that
was showing that deinit devirtualization worked to use a struct with deinit
instead of a class.

rdar://109679168
2023-05-27 22:07:04 -07:00
Dario Rexin
97381e6411 [IRGen] Support additional single payload enum cases in layout strings (#66042)
* [IRGen] Support additional single payload enum cases in layout strings

rdar://105837101

Adds layout string support for single payload enums with simple (non-scattered) extra inhabitant patterns

* Add more test cases
2023-05-23 13:17:51 -07:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Dario Rexin
883750e908 [IRGen] Reject enums with inaccessible tpye metadata in layout string… (#65016)
* [IRGen] Reject enums with inaccessible tpye metadata in layout string generation

rdar://107679697

Because we are currently handling most enums in layout strings by going through the metadata, we have to ensure that the metadata is accessible from the current module and reject the enum otherwise.

* Use proper mechanism to create and reference dylib in test

* Fix linking

* Add rpath to test dylib
2023-04-13 17:19:31 -07:00
John McCall
70497970f4 Tests for the vanishing tuples work in this PR.
Fixes rdar://107459964 and rdar://107478603.
2023-04-03 23:17:57 -04:00
Slava Pestov
a57ecb36ed IRGen: Clean up duplication in withOpaqueTypeGenericArgs() 2023-03-28 19:21:45 -04:00
Holly Borla
58abfb8f08 [Parameter Packs] Add an execution test for building and importing a library using
parameter packs.
2023-03-27 20:11:57 -07:00
Dario Rexin
2f8c1a402c [IRGen] Make pointers to accessor functions in layout strings relative (#64155)
* [IRGen] Make pointers to accessor functions in layout strings relative

rdar://106319336

Pointers embedded in static layout strings should always be relative, so layout strings can reside in read-only memory.

* Properly handle reference storage ownership

* Pass layout tag and metadata / type layout ppointers separately

* Layout string instantiation fully working

* Fix cases where hasLayoutString flag was not set when it should have

* Update include/swift/ABI/Metadata.h
2023-03-17 09:02:51 -07:00
Dario Rexin
5fe716577b [IRGen] Add layout strings for generic and resilient types (#64023)
* [IRGen] Add layout strings for generic and resilient types

rdar://105837048

* Add some corner cases

* Add flag to enable generic instantiation and some fixes

* Fix resilient types

* Fix metadata accessor function pointers in combined layout strings
2023-03-05 15:26:45 -08:00
Doug Gregor
9a91a448e3 Support initial values for stored properties of @_objcImplementation.
Fixes rdar://106108285.
2023-03-02 12:22:11 -08:00
Dario Rexin
a0e1810f62 [IRGen] Generate layout strings for subset of enums (#63930)
rdar://105959425
2023-02-27 07:33:34 -08:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Pavel Yaskevich
5dded3da73 [Tests] NFC: Remove test-cases associated with TypeWrappers feature 2023-02-08 10:14:34 -08:00
Pavel Yaskevich
5b2ce0d663 Merge pull request #62699 from xedin/type-wrapper-fixes
[SILGen/DI] TypeWrapper: Few improvements to synthesis in user-defined initializers
2022-12-20 17:46:20 -08:00
Pavel Yaskevich
01b5a9d182 [DI] TypeWrappers: Support conformance requirements on Wrapper/Storage parameters 2022-12-19 14:17:38 -08:00
Pavel Yaskevich
d1bb5add17 [SILGen] TypeWrappers: Handle initialization of property wrapped fields without init exprs
Type wrapper synthesis cannot reply on `getExecutableInit` to
determine whether initialization should use backing wrapper
call or not, it has to check whether the init expression exists.
2022-12-19 13:48:40 -08:00
Arnold Schwaighofer
1e82ef8df7 Fix dynamic replacement of weakly linked symbols
If the replaced symbol goes away in the original library, the
replacement key in the replacement descriptor will be null. Handle this
by ignoring the replacement entry rather than crashing.

rdar://103307821
2022-12-15 13:19:34 -08:00
Ellis Hoag
693a049fe4 Allow Swift to call objc_direct constructors 2022-11-17 17:05:45 -08:00
Pavel Yaskevich
c003e69d6b [Sema] TypeWrappers: Allow type wrapper inference from protocol conformances
- Infer type wrappers only from direct (declared on type) protocols
- Inferences from protocol to protocol is not allowed
- If type specifies a type wrapper attribute explicitly it has to
  match the one associated with a declared protocol, otherwise the
  declaration is going to be rejected as having multiple wrappers.
2022-11-08 16:15:56 -08:00
Pavel Yaskevich
a82d8a5eff [TypeWrappers] NFC: Remove property key path printing
Some of the key paths are printed inconsistently across
different platforms.
2022-10-21 20:04:01 +01:00
Pavel Yaskevich
34fc834f6e [AST/Sema] TypeWrappers: Use special subscript to manage storage of classes
New subscript allows to pass wrapped self instance down to the
type wrapper and is declared as follows:

```
subscript<...>(wrappedSelf <name>: Wrapped, propertyKeyPath: ..., storageKeyPath: ...)
```

The type-checker would use it to synthesize getter/setter accessors for
managed storage if wrapped type is a class.
2022-10-21 20:04:01 +01:00
Pavel Yaskevich
358346c0d5 [AST/Sema] TypeWrappers: Add propertyKeyPath parameter to type wrapper subscripts
The compiler is going to synthesize `\.<property-name>` as an argument
to `propertyKeyPath:` parameter which points to the wrapped property.
2022-10-21 20:04:01 +01:00
Pavel Yaskevich
b769f9f2e4 [Sema] TypeWrappers: Adjust synthesized type wrapper init calls to pass the wrapped type 2022-10-21 20:04:01 +01:00
Pavel Yaskevich
0f48f5c152 [AST/Sema] TypeWrappers/NFC: Rename type wrapper init parameter to storage: 2022-10-21 20:04:00 +01:00
Pavel Yaskevich
5c8c008c8e Merge pull request #61479 from xedin/type-wrappers-init-values-in-user-defined-inits
[SILGen] TypeWrappers:  Support default values in user-defined initializers
2022-10-21 08:48:35 +01:00
Becca Royal-Gordon
6143b8379f Generate IR for @_objcImpl stored properties
Only works for trivial types right now because features related to initialization and deinitialization are seriously busted.
2022-10-18 17:21:56 -07: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
Pavel Yaskevich
7dfad23828 [SILGen] TypeWrappers: Support default values in user-defined initializers
All of the property initializers are injected as initializations
of individual `_storage` fields.
2022-10-07 17:36:12 -07:00