Commit Graph

2588 Commits

Author SHA1 Message Date
Dario Rexin
38decb8ab3 [Test] Disable layout string tests on back deployment runtime (#64002)
rdar://106085766
2023-03-01 21:23:28 -08:00
Joe Groff
ecceb02e2a Implement consume x operator with the accepted SE-0366 syntax.
Implement it as a contextual operator that only parses as an operator when
followed by an identifier.
2023-03-01 17:37:54 -08:00
Kavon Farvardin
cc0b668efb Merge pull request #63922 from kavon/standard-issue-neuralyzer
Implement the `forget` statement (as `_forget`)
2023-03-01 11:10:25 -08:00
Nate Cook
3bf780572a Update requirements for a new moveonly test 2023-03-01 12:42:48 -06:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Joe Groff
0595476cd8 Update moveonly diagnostics 2023-02-28 12:48:41 -08:00
Joe Groff
03a2393a6c IRGen: Track IsCopyable through type infos.
And use the new bit to ensure we don't try to lower move-only types
with common layout value witness surrogates. Take a bit in the runtime
value witness flags to represent types that are not copyable.
2023-02-27 18:52:50 -08:00
Dario Rexin
a0e1810f62 [IRGen] Generate layout strings for subset of enums (#63930)
rdar://105959425
2023-02-27 07:33:34 -08:00
Slava Pestov
6dbdfc8fc3 Merge pull request #63911 from slavapestov/more-variadic-mangling
More variadic generics mangling changes
2023-02-25 21:44:29 -05:00
Slava Pestov
aa8f87a768 IRGen: Fix emitPackShapeExpression() with empty pack 2023-02-25 16:19:07 -05:00
Dario Rexin
96d988a431 [Runtime] Move bytecode layout handling into runtime (#63901)
rdar://105904548
2023-02-25 10:18:45 -08:00
Slava Pestov
8790101221 Merge pull request #63641 from sophiapoirier/rdar104716322_constraint_environment_assertion
pack expansion within a container type fails to type check with Const…
2023-02-25 10:30:53 -05: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
Sophia Poirier
76862384da [Variadic Generics] do not use pack element opener when resolving pattern during pack expansion type resolution 2023-02-24 15:33:42 -08:00
Joe Groff
136c179b28 Merge pull request #63840 from jckarter/irgen-struct-deinit
IRGen: Use `deinit` to destroy move-only structs that have them.
2023-02-23 08:22:20 -08:00
Joe Groff
afa5837aeb IRGen: Use deinit to destroy move-only structs that have them.
The `deinit` takes full responsibility for destroying the value, using the
user-defined deinit body and implicitly destroying any remaining resources
not consumed during the deinit.

Remaining to do after this patch:

- Run the deinit for enums
- Pass generic arguments for generic move-only types
- Handle deinits that take their parameter indirectly
- Teach value witness layout about when types are move-only and/or have
  deinits, so that we don't attempt to give move-only types standard
  value witness tables or share box metadata with copyable payloads
2023-02-22 16:48:30 -08:00
Michael Gottesman
f9f111841e [move-only] When emitting a deinit for a move only struct with only trivial fields, use an end_lifetime instead of a destructure_struct.
rdar://104875010
2023-02-22 13:36:50 -08:00
Kavon Farvardin
c948f3c04f add ownership to tests using noncopyable parameters 2023-02-16 22:08:13 -08:00
Mike Ash
72c1a05226 [Test] Mark objc_implementation_swift_client unsupported when using the OS stdlib or back deployment stdlib. 2023-02-13 12:02:22 -05:00
Becca Royal-Gordon
7d93b7543d Merge pull request #63534 from beccadax/default-is-not-init-stars
Make objcImpl classes derive inherited inits
2023-02-09 12:02:44 -08:00
Pavel Yaskevich
8eebb5bec1 Merge pull request #63522 from xedin/revert-type-wrappers
[AST/Sema/SIL] Revert TypeWrappers feature functionality
2023-02-09 09:27:18 -08:00
Erik Eckstein
d25b1ed834 Optimizer: Replace the MandatoryCombine pass with a Simplification pass, which is implemented in Swift
The Swift Simplification pass can do more than the old MandatoryCombine pass: simplification of more instruction types and dead code elimination.
The result is a better -Onone performance while still keeping debug info consistent.

Currently following code patterns are simplified:
* `struct` -> `struct_extract`
* `enum` -> `unchecked_enum_data`
* `partial_apply` -> `apply`
* `br` to a 1:1 related block
* `cond_br` with a constant condition
* `isConcrete` and `is_same_metadata` builtins

More simplifications can be added in the future.

rdar://96708429
rdar://104562580
2023-02-09 06:50:05 +01:00
Pavel Yaskevich
5dded3da73 [Tests] NFC: Remove test-cases associated with TypeWrappers feature 2023-02-08 10:14:34 -08:00
Becca Royal-Gordon
fc3ebd1995 Partially re-enable some @_objcImpl tests
These were disabled becuase they didn’t work properly in bots testing iOS or other platforms. Re-enable them for macOS until they can be fully repaired.
2023-02-06 14:54:24 -08:00
Sophia Poirier
e8361dd8cd [Variadic Generics] fix tests incorrect pack expansion syntax in some tests, but also disable them due to triggering a constraints checker assertion 2023-01-27 16:50:40 -08:00
Holly Borla
6725f365ba [Variadic Generics] Update tests for syntax changes. 2023-01-07 09:50:14 -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
Andrew Trick
d593623ffb Do not insert dynamic exclusivity checks in closure cycles
Closure cycles were originally enforced "conservatively". Real code
does, however, use recursive local functions. And it's surprisingly
easy to create false exclusivity violations in those cases.

This is safe as long as we can rely on SILGen to keep captured
variables in boxes if the capture escapes in any closure that may call
other closures that capture the same variable.

Fixes https://github.com/apple/swift/issues/61404
Dynamic exclusivity checking bug with nested functions. #61404

Fixes rdar://102056143 (assertion failure due to exclusivity checker -
AccessEnforcementSelection should handle recursive local captures)
2022-12-18 12:32:25 -08:00
Slava Pestov
b206c76eff Merge pull request #62566 from slavapestov/irgen-metadata-packs
IRGen: Sketch out metadata pack emission
2022-12-17 11:15:00 -05:00
Slava Pestov
0e72564c47 IRGen: Support for tuple metadata involving pack expansions 2022-12-17 04:13:54 -05: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
Mike Ash
f440432891 [Runtime] Fix debugDescription of .self keypaths.
AnyKeyPath's debugDescription assumes there's always at least one component, but `\Type.self` produces an empty keypath. Special-case the empty case to display a `.self` component.

rdar://103237845
2022-12-12 14:34:22 -05:00
Joe Groff
deab4cbf21 Merge pull request #62183 from ellishg/objc-direct-constructor
Allow Swift to call objc_direct constructors
2022-12-08 15:13:21 -08:00
Allan Shortlidge
164ac421d6 Sema: Lift restriction preventing use of #_hasSymbol on non-Darwin platforms.
An early approach to codegen for `#_hasSymbol` relied on the Darwin platfom SDK, but now that the feature lowers directly to NULL checks in LLVM IR a platform restriction is no longer needed.

However, the tests for `#_hasSymbol` remain unsupported on Windows since that OS does not support weak linking.
2022-11-30 14:58:28 -08:00
Ellis Hoag
693a049fe4 Allow Swift to call objc_direct constructors 2022-11-17 17:05:45 -08:00
Allan Shortlidge
3da18b6e68 SIL: Serialize and deserialize has_symbol instructions. 2022-11-16 16:07:59 -08:00
Pavel Yaskevich
e762d20568 Merge pull request #61982 from xedin/type-wrappers-on-protocols
[Sema] TypeWrappers: Allow type wrappers on protocols and inference from them
2022-11-14 12:46:48 -08:00
Allan Shortlidge
7e85fd0245 Test: Disable Interpreter/has_symbol.swift for device_run in addition to remote_run. 2022-11-12 10:46:35 -08:00
Allan Shortlidge
8b84752969 Test: Add UNSUPPORTED: remote_run to Interpreter/has_symbol.swift.
This test involves dylib manipulation so it doesn't support device testing.
2022-11-10 14:01:27 -08:00
Allan Shortlidge
936debde40 IRGen: Disable Interpreter/has_symbol.swift for optimized builds. 2022-11-09 14:21:51 -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
Allan Shortlidge
bc1168383d Sema: Relax the availability requirements for @_spi protocol witnesses.
Now that the public declarations in API libraries are checked according to the minimum possible deployment target of their clients this relaxation is needed for source compatibility with some existing code.

Resolves rdar://100904631
2022-11-07 09:04:20 -08:00
Michael Gottesman
8fa5a0e6f1 Merge pull request #61857 from gottesmm/pr-557d1bdfecfe6c7c67115122a6d499ff6c3e51f5
[move-only] Ban move only types being stored properties of copyable types or conforming to protocols
2022-11-05 00:04:21 -07:00
Michael Gottesman
51e90ee52c [move-only] Ban creating protocol conformances on move only nominal types.
I added code to the type checker that both bans this when one adds the
conformance on the nominal type declaration as well as on extensions. I was
careful to ensure we can still add extensions without an inherited clause.

Doing this until we get the full generics model.

rdar://101874019
2022-11-04 12:48:44 -07:00
Allan Shortlidge
7f20380f0b IRGen: Generate #_hasSymbol query functions.
For each decl that needs a `#_hasSymbol()` query function, emit the corresponding helper function body during IRGen. Use `IRSymbolVisitor` to collect linkable symbols associated with the decl and return true from the helper function if the address of every associated symbol is non-null.

Resolves rdar://101884587
2022-11-04 11:19:29 -07:00
Alsey Coleman Miller
62b7be4e9c [stdlib] Add RISCV64 support 2022-11-01 23:59:42 -07:00
Becca Royal-Gordon
75965d0588 Exclude overrides from being member impls
Without this change, an `@_objcImplementation` cannot override parent class methods, because the special access control behavior breaks the access control checks for overrides.
2022-10-27 17:00:43 -07:00
Pavel Yaskevich
d8cfe03beb Merge pull request #61501 from xedin/type-wrappers-add-wrapped-type
[AST/Sema] TypeWrappers: Extend implementation to support wrapped type
2022-10-27 08:55:38 -07:00