Commit Graph

1470 Commits

Author SHA1 Message Date
Slava Pestov
c2f1193ae3 Merge pull request #67952 from slavapestov/tuple-conformance-tbd-etc
A pile of mostly unrelated one-liners
2023-08-18 15:31:26 -04:00
Slava Pestov
212b10a7fc TBDGen: Pass useResolver=true to forEachValueWitness() 2023-08-18 12:12:50 -04:00
Slava Pestov
30ec935b81 TBDGen: Use IterableDeclContext::getABIMembers() instead of getMembers() 2023-08-18 12:12:50 -04:00
Slava Pestov
99d68ba14c IRGen: Some progress toward tuple conformances 2023-08-18 12:12:50 -04:00
zachary0kent
802e63a778 Merge pull request #67973 from zachary0kent/lazy-immediate-globals
[Immediate] JIT'ing Globals
2023-08-18 08:53:18 -07:00
nate-chandler
8cab09e429 Merge pull request #67966 from nate-chandler/opaque-values/20230816/1/indirect-pack-tuple-handling
[AddressLowering] Handle indexing into variadic tuples.
2023-08-17 14:20:44 -07:00
Zak Kent
6aafeec181 [Immediate] [SILGen] Implement on-demand compilation of globals 2023-08-17 11:03:11 -07:00
Zak Kent
e276c79939 [SIL] [Immediate] Promote linkage of SILFunctions defining requested symbols
Promotes the linkage of `SILFunction`s defining requested symbols,
ensuring they are emitted during IRGen.
2023-08-17 10:11:29 -07:00
Doug Gregor
b126a0f34b Merge pull request #67977 from DougGregor/extension-macro-conformances-and-witnesses
[Macros] Fix handling of extension macro conformances and witnesses
2023-08-16 22:46:06 -07:00
zachary0kent
25f078adb5 Merge branch 'main' into lazy-immediate 2023-08-16 19:45:27 -07:00
Doug Gregor
b7bfaf3522 [Macros] Fix handling of extension macro conformances and witnesses
Fix two inter-related issues with extension macros that provide
conformances to a protocol, the combined effect of which is that one
cannot meaningfully provide extension macros that implement
conformances to a protocol like Equatable or Hashable that also
supports auto-synthesis.

The first issue involves name lookup of operators provided by macro
expansions. The logic for performing qualified lookup in addition to
unqualified lookup (for operators) did not account for extension
macros in the same manner as it did for member macros, so we would not
find a macro-produced operator (such as operator==) in witness
matching.

The second issue is more fundamental, which is that the conformance
lookup table would create `NormalProtocolConformance` instances for
pre-macro-expansion conformance entries, even though these should
always have been superseded by explicit conformances within the macro
expansion buffers. The end result is that we could end up with two
`NormalProtocolConformance` records for the same conformance. Some
code was taught to ignore the pre-expansion placeholder conformances,
other code was not. Instead, we now refuse to create a
`NormalProtocolConformance` for the pre-expansion entries, and remove
all of the special-case checks for this, so we always using the
superseding explicit conformances produced by the macro expansions (or
error if the macros don't produce them).

Fixes rdar://113994346 / https://github.com/apple/swift/issues/66348
2023-08-16 19:18:36 -07:00
Pavel Yaskevich
c38b9b1e08 Merge pull request #67945 from xedin/remove-runtimeMetadata
[Frontend] NFC: Remove code and tests related to rejected @runtimeMetadata feature
2023-08-16 17:16:46 -07:00
Nate Chandler
7bddaf36a0 [SIL] Added tuple_pack_extract.
The new instruction is needed for opaque values mode to allow values to
be extracted from tuples containing packs which will appear for example
as function arguments.
2023-08-16 11:15:05 -07:00
Allan Shortlidge
e2bb7e8c8b SILOptimizer: Remove switch cases matching unavailable enum elements.
Unavailable enum elements cannot be instantiated at runtime without invoking
UB. Therefore the optimizer can consider a basic block unreachable if its only
predecessor is a block that terminates in a switch instruction matching an
unavailable enum element. Furthermore, removing the switch instruction cases
that refer to unavailable enum elements is _mandatory_ when
`-unavailable-decl-optimization=complete` is specified because otherwise
lowered IR for these instructions could refer to enum tag accessors that will
not be lowered, resulting in a failure during linking.

Resolves rdar://113872720.
2023-08-15 17:13:10 -07:00
Pavel Yaskevich
23d838af32 [SIL/SILGen] [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:17:31 -07:00
Zak Kent
148cd6acc4 [Immediate] [Sema] Implemented Lazy Type Checking
Implements lazy type checking in Swift Immediate mode,
allowing functions to be type-checked as they are
executed.
2023-08-14 13:28:22 -07:00
Slava Pestov
1b8e9a2964 SIL: Fixes for tuple conformances 2023-08-09 17:42:25 -04:00
Nate Chandler
f938287710 [SIL] Added unowned_copy_value. 2023-08-08 15:49:17 -07:00
Nate Chandler
c007bae723 [SIL] Added weak_copy_value.
The new instruction wraps a value in a `@sil_weak` box and produces an
owned value. It is only legal in opaque values mode and is transformed
by `AddressLowering` to `store_weak`.
2023-08-08 15:47:13 -07:00
Nate Chandler
e135c5cac7 [SIL] Added strong_copy_weak_value.
The new instruction unwraps an `@sil_weak` box and produces an owned
value. It is only legal in opaque values mode and is transformed by
`AddressLowering` to `load_weak`.
2023-08-08 15:47:13 -07:00
Nate Chandler
28a1db8dd3 [IRGen] Exiting terminators don't alloc packs.
Function exiting terminators don't allocate on-stack pack metadata
packs.  The packs would have been materialized when the value is
defined.

Fixes a SILVerifier failure resulting from a sequence like
```
alloc_pack_metadata
dealloc_pack_metadata
return
```
resulting from inserting the `alloc_pack_metadata` on behalf of the
return, inserting the `dealloc_pack_metadata` on the dominance frontier,
and fixing up stack nesting.
2023-08-07 12:46:35 -07:00
Allan Shortlidge
cb7982d8d5 Merge pull request #67761 from tshortli/ast-unavailable-decl-queries
NFC: Hoist queries for unavailable decl optimizations into the AST library
2023-08-06 10:01:27 -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
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Anton Korobeynikov
03334a8f92 [AutoDiff] Generalize handling of semantic result parameters (#67230)
Introduce the notion of "semantic result parameter". Handle differentiation of inouts via semantic result parameter abstraction. Do not consider non-wrt semantic result parameters as semantic results

Fixes #67174
2023-08-03 09:33:11 -07:00
nate-chandler
b14c34a592 Merge pull request #67660 from nate-chandler/opaque-values/20230801/2/rewrite_consuming_uses_last
[AddressLowering] Rewrite lifetime-ends last.
2023-08-02 07:04:52 -07:00
Joe Groff
aa397c763e Merge pull request #67657 from jckarter/sil-type-consolidate-move-only-predicate
Remove redundant SILType::isMoveOnlyNominalType (NFC)
2023-08-01 17:33:34 -07:00
Nate Chandler
6aa44d83c9 [AddressLowering] Rewrite lifetime-ends last.
Previously, `end_borrow`s were rewritten last in order to be able to
find them when inserting `end_borrow`s on behalf of newly created
`load_borrow`s. Generalize this to rewriting all lifetime-ending users
last.  This is necessary for the lifetime utilities used by `isLoadCopy`
to remain accurate when rewriting a `copy_value` previously determined
to be from a load-copy pair.
2023-08-01 14:51:00 -07:00
Joe Groff
03eec7da2b Remove redundant SILType::isMoveOnlyNominalType (NFC)
and implement `SILType::isPureMoveOnly` in terms of `Type::isPureMoveOnly`.
2023-08-01 14:07:38 -07:00
Joe Groff
984b4f2387 Merge pull request #67633 from jckarter/raw-layout-initialization
Fix `@_rawLayout` initialization to avoid spurious lifetime ends.
2023-08-01 13:34:29 -07:00
Joe Groff
9b783560ad Fix @_rawLayout initialization to avoid spurious lifetime ends.
We can't really treat them as always-initialized because that makes move checking
think that there's a value to destroy even on initialization, causing deinits to
run on uninitialized memory. Remove my previous hack, and use a `zeroInitializer`
to initialize the value state when emitting `init`, which is where we really need
the bootstrapping-into-initialized behavior. rdar://113057256
2023-08-01 08:34:02 -07:00
Pavel Yaskevich
a22bd2741e Merge pull request #67593 from xedin/textual-sil-assign_or_init
[SIL] InitAccessors: Support `assign_or_init` in textual SIL
2023-07-31 09:11:44 -07:00
nate-chandler
5116600284 Merge pull request #67583 from nate-chandler/checked_cast_br/formal-source
[SIL] Add source formal type to checked_cast_br.
2023-07-28 10:54:06 -07:00
Pavel Yaskevich
36f65b32f8 [SIL] InitAccessors: Adjust SIL printer/parser to support "field" of assign_or_init instruction 2023-07-28 09:34:00 -07:00
Pavel Yaskevich
ddad2a7dad [SIL] InitAccessors: Reference a field that assign_or_init is associated with
The field removes the need to dig through init accessor reference
to find what stored properties and handled by the instruction.
2023-07-28 08:32:37 -07:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Nate Chandler
928bcf31b1 [IRGen] Insts with packs in ops/results may alloc.
Instead of assuming that the list of instructions known to allocate pack
metadata is exhaustive and returning false from mayRequirePackMetadata
for all others, consider the types of the results and operands of other
instructions and look for packs.
2023-07-27 14:02:18 -07:00
Nate Chandler
471c9789c7 [AST] NFC: Refactor pack recursive properties.
Eliminated HasConcretePack and added HasPack and HasPackArchetype.
Renamed the old `hasPack` to `hasAnyPack`; as before, it means that the
type has a parameter pack, a pack, or a pack archetype.
2023-07-27 13:18:14 -07:00
Nate Chandler
ad2223d854 [IRGen] alloc_stack may allocate pack metadata.
When it's a tuple containing a pack.
2023-07-27 08:34:15 -07:00
Joe Groff
705e317c3f Merge pull request #67425 from jckarter/raw-storage
[WIP] Raw storage and locks/atomics prototype
2023-07-26 08:49:02 -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
Nate Chandler
3f069df550 [IRGen] Add metadata pack markers for destroys.
Destroys of values whose types feature a pack may require allocating the
pack on-stack.

Thanks to @slavapestov for the test case.

rdar://112792831
2023-07-24 14:19:24 -07:00
Nate Chandler
90d5d86bd8 [IRGen] NFC: Unified unary instructions.
In preparation for adding addition unary instructions which
`mayRequirePackMetadata`, group the instructions which already may
produce pack metadata depending on their single operand's type together.
2023-07-24 14:15:51 -07:00
Michael Gottesman
7aea9d44c3 Merge pull request #67414 from gottesmm/rdar112555589-112547982
[move-only] Fix two small errors around handling capturing of noncopyable self by local functions
2023-07-19 21:28:09 -07:00
Michael Gottesman
6675084af8 [move-only] Do not try to capture self as an immutable box.
The problem here is that the logic was conditionalized on all noncopyable
parameters that are borrowed as having the ValueOwnership::Shared flag set. This
is only true for user written parameters. Implicit noncopyable parameters like
self do not have ValueOwnership::Shared set upon them. We could potentially do
that in Sema, but Sema does not know what the proper convention of self is since
that information is in TypeLowering today.

With that in mind, conditionalize the logic here so we do the right thing.

rdar://112547982
2023-07-19 14:21:26 -07:00
Slava Pestov
04fe8f4bc6 SIL: Add forEachExpandedPackElement() and use it in type lowering
Probably there's no way to hit this right now, but there will be if
concrete formal PackTypes start showing up in AST.
2023-07-19 16:24:38 -04:00
Slava Pestov
8a07466938 SIL: Fix SubstFunctionTypePatternVisitor handling of pack types
The included test case also covers the previous commit.
2023-07-19 16:24:27 -04:00
Slava Pestov
fff8a4ae96 SIL: Don't attempt to emit keypath descriptors with unsupported reabstraction thunks 2023-07-19 12:40:28 -04:00
Slava Pestov
76c90f6024 Merge pull request #67362 from slavapestov/sil-pattern-count-abstraction
SIL: Fix substituted function type visitor for PackExpansionType with concrete pattern type
2023-07-19 07:49:27 -04:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00