Commit Graph

34 Commits

Author SHA1 Message Date
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Pavel Yaskevich
65cfb1cf10 [RawSILLowering] InitAccessors: guard against situations when emitBeginBorrowOperation returns back original value
Calling `emitBeginBorrowOperation` on something which is `load_borrow`
for example with guaranteed ownership doesn't produce `begin_borrow`
instruction, so we need to be careful not to emit mismatched `end_borrow`
in such cases.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
28a39d6df1 [AST] NFC: Add a way to request initialized/accesses properties from init accessor 2023-07-07 10:00:36 -07:00
Pavel Yaskevich
135f2c2ea0 [SILGen] InitAccessors: Start supporting assign_or_init for properties without a setter
Implement "init accessor" component emission which is paired with
"init accessor" write strategy. Use `SILUndef` for a "setter" operand
of an "assign_or_init" instruction in cases when property with init
accessor doesn't have a setter. DI would detect re-initialization
attempts to produce diagnostics.
2023-07-03 22:07:19 -07:00
Pavel Yaskevich
80a1e2c2ba [SILGen] InitAccessors: Produce partial apply of init accessor ref to produce substituted closure
Instead of dealing with substitutions during raw SIL lowering,
let's produce a partial apply without argument to produce a
substituted reference that could be used by SILVerifier and
raw SIL lowering stages.
2023-06-28 12:28:15 -07:00
Pavel Yaskevich
3063e9d778 [SIL] InitAccessors: Reference "self" in assign_or_init instruction
First step on the path to remove dependence on "setter".
2023-06-27 09:45:05 -07:00
Pavel Yaskevich
c82559e33c [DI/Lowering] InitAccessors: Implement lowering of property assignments
DI marks all of of the previously initialized properties and Raw SIL
lowering emits `destroy_addr` before calling init accessor for such
properties to destroy previously set value.
2023-06-06 18:59:46 -07:00
Pavel Yaskevich
73765c8028 [SIL] InitAccessors: Fix reference type handling by DI and RawSIL lowering
- Adds a missing check to `collectClassSelfUses` to find assign_or_init instructions;
- RawSIL lowering should start emitting access around synthesized member references.
2023-06-06 18:59:45 -07:00
Pavel Yaskevich
2e8b0e716f [RawSILLowering] InitAccessors: Implement lowering of assign_or_init as init accessor call 2023-06-06 18:59:13 -07:00
Holly Borla
df69020eca [DefiniteInitialization] Lower AssignOrInit instructions to either call the
initializer or the setter closure with the given argument.
2023-06-06 18:59:13 -07:00
Holly Borla
ac66a06199 [SIL] Add a new AssignOrInit instruction for init accessors.
This instruction is similar to AssignByWrapperInst, but instead of having
a destination operand, the initialization is fully factored into the init
function operand. Like AssignByWrapper, AssignOrInit has partial application
operands of both the initializer and the setter, and DI will lower the
instruction to a call based on whether the assignment is initialization or
a setter call.
2023-06-06 18:59:10 -07:00
Pavel Yaskevich
e0bf2ff854 [SIL/DI] NFC: Remove TypeWrappers feature functionality 2023-02-08 10:14:29 -08:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Pavel Yaskevich
d1ad9e3e4d [SILOptimizer] TypeWrappers: Lower assign_by_wrapper into copy_addr for address-only types 2022-09-29 20:50:37 -07:00
Pavel Yaskevich
fe1f150664 [SILOptimizer] Implement lowering of type wrapper assignment instructions
Type wrapper originated assignment instructions are lowered similar
to property wrapper ones except they don't require initializer call
because assignments are done to tuple fields.
2022-09-29 20:50:36 -07:00
Erik Eckstein
b12b4e95b9 Don't crash in RawSILInstLowering if DI produced an error.
In case DI doesn't classify assign_by_wrapper (because of another error), make sure that RawSILInstLowering can handle this.

rdar://75433096
2021-03-16 13:28:52 +01:00
Erik Eckstein
ad8252654d RawSILInstLowering: delete dead load instructions when lowering assign_by_wrapper
If only the init-closure is used and the setter-closure is dead, the argument to the setter partial_apply also needs to be delete - in case it's a load.
Otherwise it would cause a memory lifetime failure.
2021-03-13 10:41:30 +01:00
Erik Eckstein
9055e93af9 SIL: some improvements/fixes around assign_by_wrapper
* Refactoring: replace "Destination" and the ownership qualifier by a single "Mode".  This represents much better the mode how the instruction is to be lowered. NFC
* Make assign_by_wrapper printable and parseable.
* Fix lowering of the assign modes for indirect results of the init-closure: The indirect result was initialized and not assigned to. The fix is to insert a destroy_addr before calling the init closure. This fixes a memory lifetime error and/or a memory leak. Found by inspection.
* Fix an iterator-invalidation crash in RawSILInstLowering
* Add tests for lowering assign_by_wrapper.
2021-03-03 18:57:02 +01:00
Erik Eckstein
fa11bdff1a RawSILInstLowering: delete an unused partial_apply when lowering assign_by_wrapper
So far we left this cleanup to SILCombine.
But the unused partial_apply (i.e. the "set" in case it's an init or the "init" in case it's a set) violates memory lifetime rules in case "self" is an inout.
Once we verify that, it would result in a memory lifetime violation.
2021-03-02 12:02:54 +01:00
Andrew Trick
f92009da98 Remove SILArgumentConvention::Direct_Deallocating 2020-12-08 13:41:47 -08:00
Holly Borla
1f426773ee [Property Wrappers] Lower assign_by_wrapper to re-assignment of the backing
property wrapper before all of self is initialized if the wrapper has already
been initialized.
2020-09-11 15:43:21 -07:00
Erik Eckstein
282907fc0a Fix property wrappers with tuples.
In case of a tuple as value type, the initializer and setter takes the tuple elements as separate arguments. This was just not handled in the assign_by_wrapper instruction lowering.

rdar://problem/53866473
2019-08-08 21:46:08 +02:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Slava Pestov
472787bab7 SIL: isNonThrowing parameter of SILBuilder::create{Begin,}Apply() defaults to false
Also remove the overload of createApply() that does not take a SubstitutionMap.
It accomplishes nothing except creating ambiguity.
2019-04-25 22:27:38 -04:00
Doug Gregor
03f674018b Eliminate a use-after-free in assign_by_delegate lowering.
ASan is magic. Thank you, ASan.
2019-04-23 11:32:28 -07:00
Erik Eckstein
e1674232c7 RawSILInstLowering: lower assign_by_delegate 2019-04-23 11:32:28 -07:00
Slava Pestov
8915f96e3e SIL: Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction) 2019-03-12 01:16:04 -04:00
Azoy
5af2663c57 Textualize assign init kind
Rename [assign] to [reassign]

fix some tests

AssignOwnershipQualifier

formatting

moar formatting
2019-02-12 20:16:25 -06:00
Azoy
fcd6a8adf3 Lower Assign to store [assign] & Remove MandatoryOptUtils
update debug_type
2019-02-12 18:10:17 -06:00
Azoy
397b96c917 [SILOptimizer] Don't lower AssignInst in DI 2019-02-12 18:10:17 -06:00
Michael Gottesman
2872389826 [definite-init] Split raw SIL instruction lowering out of DI into its own pass run after DI.
I am doing this so I can start writing DI tests without this lowering occuring.
There never was a real reason for this code to be in DI beyond convenience. Now
it just makes writing tests more difficult. To prevent any test delta, I changed
all current DI tests to run this pass after DI.
2018-05-22 18:18:22 -07:00