Commit Graph

2864 Commits

Author SHA1 Message Date
Pavel Yaskevich
4ec86f222a [DI] InitAccessor: Ignore a load of "self" introduced by a partial apply of a setter
`nonmutating set` needs to load of "self" but that load could be
ignored safely because it's only viable when self is determined
to be fully initialized by DI. The same applies to `assign_by_wrapper`.
2023-08-25 09:49:31 -07:00
swift-ci
86d56fd677 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-24 12:33:30 -07:00
Michael Gottesman
80f4588d0f Merge pull request #68104 from gottesmm/pr-b947139b791a295a9644ab3e87505ccaed9e9259
[send-not-sendable] Eliminate relative includes and add a file header.
2023-08-24 12:17:14 -07:00
Michael Gottesman
373a007efa [send-not-sendable] Eliminate relative includes and add a file header.
Specifically, the two routines we were importing relatively were:

1. TypeChecker::conformsToProtocol. I moved this onto a helper routine on
SILType.

2. swift::findOriginalValueType(Expr *). This routine just looks through various
implicit conversions to find the original underlying type. I moved it to a
helper method on Expr.
2023-08-23 14:38:30 -07:00
swift-ci
3dd9682bbe Merge remote-tracking branch 'origin/main' into rebranch 2023-08-21 21:13:58 -07:00
nate-chandler
1f05436a99 Merge pull request #68049 from nate-chandler/opaque-values/20230821/1/all-local-archetypes
[AddressLowering] Consider opening instructions of all local archetypes.
2023-08-21 20:55:25 -07:00
swift-ci
a083336db3 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-21 14:33:27 -07:00
Nate Chandler
efc9c6df10 [AddressLowering] Consider all local archetypes.
When determining where the "latest opening instruction" is, consider not
just `OpenedArchetypeType`s but any `LocalArchetypeType` which includes
`PackArchetypeType`s.
2023-08-21 13:46:11 -07:00
swift-ci
5dbdcd9012 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-21 09:15:49 -07:00
Pavel Yaskevich
2149a4630a [DI] InitAccessors: Ignore unreachable blocks when check property initialization inside of an init accessor 2023-08-21 09:04:34 -07:00
Pavel Yaskevich
1542bb5a71 Merge pull request #67763 from xedin/rdar-113412104
[DI] Properties with init accessors without "initializes" act as stored
2023-08-21 09:03:43 -07:00
swift-ci
2f4bd434fa Merge remote-tracking branch 'origin/main' into rebranch 2023-08-20 21:34:05 -07:00
Michael Gottesman
361562aef5 [consume-operator] Emit a better error message when failing to consume globals or escaping captures.
Specifically, we previously emitted a "compiler doesn't understand error", so we
were always emitting an error appropriately. This just gives a better error
message saying instead that the compiler did understand what happened and that
one cannot apply consume to globals or escaping captures.

https://github.com/apple/swift/issues/67755
rdar://112561671
2023-08-20 18:59:37 -07:00
swift-ci
5c79bc3e80 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-18 02:36:36 -07:00
Erik Eckstein
1603035927 PerformanceDiagnostics: fix handling of nested closures
Need to handle `mark_dependence` instruction in the use-def walk for the closure value.

Fixes a false performance error.

rdar://114008787
2023-08-18 09:08:04 +02:00
swift-ci
9d38c6b53e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-17 14:34:52 -07:00
Nate Chandler
84ab0eb548 [AddressLowering] Handle tuple_pack_extract.
By analogy with tuple_extract, transform the new instruction to
tuple_pack_element_addr.
2023-08-16 17:28:00 -07:00
swift-ci
7283643631 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 09:14:19 -07:00
Allan Shortlidge
117a5ecdae Merge pull request #67920 from tshortli/unavailable-decl-opt-complete-resilient-enum-switch
SILOptimizer: Remove switch cases matching unavailable enum elements
2023-08-16 09:06:20 -07:00
swift-ci
c5f45eb8e3 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 07:18:10 -07:00
Allan Shortlidge
29374cb802 SILOptimizer: Skip unreachable cases optimization when elements are available.
Cache a bit on `EnumDecl` indicating whether there are any elements that are
unavailable during lowering and then use that bit to decided whether to attempt
optimization for `switch_enum`/`switch_enum_addr` instructions.
2023-08-15 17:13:10 -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
Nate Chandler
35113d8a80 [AddressLowering] Fix partial_apply arg indexing.
When rewriting arguments, the index used is into the callee's argument
list.  For full applies, that is identical to the index into the
instruction's argument list.  For partial applies, it is not.

Previously, though, the index was used as if it were an index into the
instruction's argument list to get an argument ref.  Here, use instead
the newly added convenience to get the argument ref using the index into
the callee's arguments.
2023-08-15 13:06:32 -07:00
Nate Chandler
5c31339028 [AddressLowering] Loosen assert for partial_apply.
Full apply instructions have the same number of arguments as the callee
has parameters.  Partial apply instructions have some number less than
or equal to the number of callee parameters.
2023-08-15 13:06:32 -07:00
swift-ci
7b3a1c5362 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-14 16:38:28 -07:00
Nate Chandler
16bd80d945 [AddressLowering] Rewrite indirect partial_apply.
In opaque values mode, all arguments are passed to a partial_apply (just
like all other flavors of apply) directly.  AddressLowering needs to
rewrite the operands whose convention is indirect as it does for other
applies.
2023-08-14 10:40:40 -07:00
swift-ci
1c884ad96f Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 14:13:26 -07:00
nate-chandler
72bcb756f5 Merge pull request #67831 from nate-chandler/opaque-values/20230809/opaque-result-types
[AddressLowering] Type SILFunctionArguments for @out results with opaque types substituted.
2023-08-11 14:09:04 -07:00
Nate Chandler
fa98212420 [AddressLowering] Look through opaque result type.
A function which returns a value of opaque result type

    func f() -> some P { S() }

has a lowered, substituted signature

    @convention(thin) () -> @out @_opaqueReturnTypeOf("$s4main1fQryF", 0) opaque

featuring an _opaqueReturnTypeOf attr.  The SILFunctionArgument for that
@out result, however, must be of the type that the opaque result
substitutes to in the expansion context of the function.
2023-08-11 08:10:38 -07:00
swift-ci
4fe55c5732 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 00:35:20 -07:00
swift-ci
2667df0799 Merge pull request #67760 from atrick/fix-closure-moveonly-arg
Fix compiler crashes with consuming and borrowing keywords.
2023-08-11 00:32:41 -07:00
swift-ci
525350af1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 22:14:25 -07:00
Andrew Trick
f46d79149d ClosureLifetimeFixup review feedback 2023-08-10 18:51:48 -07:00
Michael Gottesman
33eedc1574 Merge pull request #67874 from gottesmm/pr-179e2ec3ed29bb0d8c35dc99f710a18571a0a24e
[sil] Convert AddressWalker from using virtual methods to use CRTP and add a transitive -> endpoint user API
2023-08-10 17:18:27 -07:00
swift-ci
7d6771cf8e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 15:37:51 -07:00
Michael Gottesman
29350907fc Convert TransitiveAddressWalker to use CRTP instead of virtual functions. 2023-08-10 12:58:50 -07:00
Nate Chandler
dfa629a197 [SIL] Fix memInstMustInitialize for builtins.
The function's switch previously fell-through to the
SILInstructionKind::StoreWeakInst case which cast the instruction (a
BuiltinInst) to StoreWeakInst and then called isInitializationOfDest on
it.
2023-08-10 12:27:03 -07:00
Andrew Trick
83ce3a1777 Rename getArgumentOperandConvention to getCaptureConvention
The name was misleading and problematic. There is already a
getArgumentConvention which is completely different.
2023-08-10 11:17:53 -07:00
Andrew Trick
9c24933bd4 Fix compiler crashes with consuming and borrowing keywords.
Without this fix, the new 'consuming' and 'borrowing' keywords cannot
be used with trivial types. Which means, for example, they can't be
used in macro expansions that work on various types.

Fixes patterns like:

public func test1(i: consuming Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test2(i: borrowing Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test3(i: consuming Int) -> Int {
  takeClosure { i }
}

// Sadly, test4 is still incorrectly diagnosed.
public func test4(i: borrowing Int) -> Int {
  takeClosure { i }
}

Fixes rdar://112795074 (Crash compiling function that has a macro annotation and uses `consuming`)
2023-08-10 11:17:45 -07:00
swift-ci
a4bb99bd1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-09 07:15:49 -07:00
Nate Chandler
57c7c9e730 [AddressLowering] Handle unowned copies.
Lower the `strong_copy_unowned_value` and `unowned_copy_value` to
`load_unowned` and `store_unowned` respectively.
2023-08-08 15:49:17 -07:00
Nate Chandler
390d02f114 [AddressLowering] Handle weak copies.
Lower the `strong_copy_weak_value` and `weak_copy_value` to `load_weak`
and `store_weak` respectively.
2023-08-08 15:47:13 -07:00
Pavel Yaskevich
11f1b08ada [DI] Properties with init accessors without "initializes" act as stored
Adjust DI to treat init accessor properties that have only 'accesses'
or no restrictions as if they are stored properties, this means that
if such property doesn't have a default initializer users would have
to reference it explicitly in their custom initializers.

We also need to suppress default init synthesis for such cases which
would be done in a followup commit.

Resolves: rdar://113401979
2023-08-04 21:05:07 -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
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
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
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