Commit Graph

6754 Commits

Author SHA1 Message Date
swift-ci
d4bb2bb86b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-06 10:14:39 -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
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04: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
Becca Royal-Gordon
3eebc6dddb Merge branch 'main' into rebranch
# Conflicts:
#	lib/SILOptimizer/Differentiation/Common.cpp
2023-08-04 15:09:50 -07:00
Michael Gottesman
c9be4bda49 Merge pull request #67677 from gottesmm/borrowed-base-silgenlvalue
[move-only] Ensure that we properly nest accesses to base values if the base is noncopyable or the accessor result is noncopyable.
2023-08-04 12:26:19 -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
Nate Chandler
8c2ed17c9a [OpaqueValues] Open opaque existential value.
When a value's preferred existential representation is opaque, if the
value is not an address (which can only happen in opaque values mode),
emit open_existential_value rather than open_existential_addr.
2023-08-04 08:26:35 -07:00
Nate Chandler
4c6fc1ae8b [OpaqueValues] Skip keypath lvalue temporary.
When emitting key-path functions on behalf of a base that's an l-value,
copy the l-value into a temporary only when using lowered addresses.
2023-08-03 06:25:26 -07:00
swift-ci
990b309d03 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-03 01:33:10 -07:00
swift-ci
c2fc7ee9e7 Merge pull request #67664 from nate-chandler/opaque-values/20230801/3/cxx-interop-1
[OpaqueValues] Two tweaks to enable std::vector<uint32_t> iteration.
2023-08-03 01:28:20 -07:00
swift-ci
87b23c5cf5 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 20:38:43 -07:00
Nate Chandler
51ff57856d [OpaqueValues] Don't emit temporary in one case.
When creating a foreign-to-native thunk, create a temporary when the
foreign convention is indirect-non-inout only when using lowered
addresses.
2023-08-02 20:16:58 -07:00
Nate Chandler
cc3038dcf6 [OpaqueValues] Transforms emit addr-only loads.
In opaque values mode, when transforming, load address even when their
type is address-only.
2023-08-02 20:16:58 -07:00
Nate Chandler
0ae2c0748d [OpaqueValues] Keypath setters observe triviality.
When constructing r-values during keypath setter emission, consider
whether the argument's type is trivial and construct the relevant
r-value based on that.  This worked before without opaque values because
the value is always an address.
2023-08-02 13:45:35 -07:00
Nate Chandler
aba12b3398 [OpaqueValues] Use silConv for keypath args.
Replace direct calls to SILParamInfo::getSILStorageType with calls to
SILModuleConventions::getSILType for keypath functions.
2023-08-02 13:45:35 -07:00
Michael Gottesman
c3d2276241 [silgen] Eliminate two more cases around subscripts where we were not borrowing.
Also, the store_borrow work in the previous patch caused some additional issues
to crop up. I fixed them in this PR and added some tests in the process.
2023-08-02 11:09:31 -07:00
swift-ci
9b89d2991e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 07:57:11 -07:00
nate-chandler
d4198261c0 Merge pull request #67665 from nate-chandler/opaque-values/20230801/4/keypath-setter-takes-new-value-direct
[OpaqueValues] Skip temporary when setting the value at a key-path.
2023-08-02 07:47:25 -07:00
Nate Chandler
53522638fe [OpaqueValues] Skip temp when setting at key-path.
When setting a value at a key-path, in opaque values mode, don't create
a temporary and store the new value into it.  That is necessary when
using lowered addresses because intrinsic's signature is

```
sil @swift_setAtWritableKeyPath : $@convention(thin) <τ_0_0, τ_0_1> (@inout τ_0_0, @guaranteed WritableKeyPath<τ_0_0, τ_0_1>, @in τ_0_1) -> ()
```

but is incorrect in opaque values mode where values are passed directly
to `@in` parameters.
2023-08-01 17:16:51 -07:00
swift-ci
2919af9fa7 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 13:36:46 -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
Michael Gottesman
26081ffb82 [silgen] Teach accessor projection to use store_borrow if it has a non-tuple.
This prevents another type of copy of noncopyable value error.

I also as a small change, changed the tuple version to use a formal access
temporary since we are projecting a component out implying that the lifetime of
the temporary must end within the formal access. Otherwise, we cause the
lifetime of the temporary to outlive the access. This can be seen in the change
to read_accessor.swift where we used to extend the lifetime of the destroy_addr
outside of the coroutine access we are performing.
2023-07-31 14:23:11 -07:00
swift-ci
20e81af228 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-31 09:13:49 -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
swift-ci
1ead4ffed7 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 10:57:58 -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
swift-ci
f322b91dfc Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 08:34:08 -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
Pavel Yaskevich
8af81a39ce Merge pull request #67585 from xedin/rdar-112984795
[SILGenConstructor] InitAccessors: Make sure that accessed fields are initialized before init accessors
2023-07-28 08:26:53 -07:00
Pavel Yaskevich
f6017cc69f [SILGenConstructor] InitAccessors: Make sure that accessed fields are initialized before init accessors
Initializations for all of the fields accessed by init accessor
should be emitted before init accessor property even if they are
declared after it in the source order.

Resolves: rdar://112984795
2023-07-27 15:25:52 -07:00
Pavel Yaskevich
3bb81e3c63 [SILGenConstructor] NFC: Extract initialization of individual fields into a method
This is a preliminary step in order to enable re-ordering of initializations
when init accessors are involved.
2023-07-27 15:22:14 -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
Michael Gottesman
55892ef30d [silgen] Add a special visitor for accessing the base of noncopyable types.
We want these to be borrowed in most cases and to create an appropriate onion
wrapping. Since we are doing this in more cases now, we fix a bunch of cases
where we used to be forced to insert a copy since a coroutine or access would
end too early.
2023-07-27 10:00:28 -07:00
swift-ci
1969199a8e Merge remote-tracking branch 'origin/main' into rebranch 2023-07-26 23:13:08 -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
Evan Wilde
9b61bb4b8d More llvm::Optional::transform -> swift::transform
Translating more llvm::Optional::transform calls to swift::transform.
`llvm::Optional` had a transform function that ran a lambda on the
element stored in the optional if it existed. After migrating to
std::optional under the hood, that function went away. Replacing it with
calls to swift::optional in STLExtras.h.
2023-07-25 12:28:27 -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
Holly Borla
9eb9ba23c5 [SILGen] Expand magic literals like #file and #line to values in the outermost
source file.

Values inside macro expansion buffers are not useful.
2023-07-20 20:56:41 -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
Pavel Yaskevich
b6edb098cf Merge pull request #67294 from xedin/default-init-via-accessor-in-custom-initializers
[Sema/SIL] InitAccessors: Support default initialization of init accessor properties
2023-07-19 15:32:33 -07:00
Michael Gottesman
b060e5ba60 [move-only] Make sure we mark local function inout parameters with mark_must_check.
Originally, we were relying on capture info to determine if we needed to insert
this mark_must_check. This ignored that the way that we are handling
escaping/non-escaping is something that is approximated in the AST but actually
determined at SIL level. With that in mind, rather than relying on the capture
info here, just rely on us having an inout argument. The later SIL level
checking for inout escapes is able to handle mark_must_check and knows how to
turn off noncopyable errors in the closure where we detect the error to prevent
us from emitting further errors due to the mark_must_check here.

I discovered this while playing with the previous commit.

rdar://112555589
2023-07-19 15:02:04 -07:00
nate-chandler
d13348c074 Merge pull request #62494 from nate-chandler/opaque-values/2/20221209
[OpaqueValues] Initial support for AD.
2023-07-19 07:12:37 -07:00
John McCall
a934f1f66c Merge pull request #67368 from rjmccall/unimplementable-variadic-reabstraction
Diagnose attempts to reabstract variadic functions in unimplementable ways
2023-07-18 21:28:59 -04:00
Pavel Yaskevich
c87daab11c [SILGen] InitAccessors: Don't use init accessor to initialize superclass properties
`super.init()` should fully initialize "super" which means that
such properties are mutated via a setter.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
aa52e42b3e [SILGen] InitAccessors: Start emitting init property initialization expressions
Similar to regular stored properties emit initialization expressions
for properties with init accessors at constructor's prolog.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
1f87ee8ca3 [SILGen] InitAccessors: Extract emission of assign_or_init into a separate method
New method is going to be used to emit default value initializations
for user-defined constructors.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
5fd502b150 [SILGen] InitAccessors: Generalize AccessorComponent::emitValue
Instead of taking a setter type, let's switch over to a more general
`AccessorKind` which allows us to cover init accessors and simplify
`emitApplySetterToBase`.
2023-07-18 17:19:42 -07:00