Commit Graph

6516 Commits

Author SHA1 Message Date
WeZZard
2237faca04 [SILOptimizer] Refines the implementation of of the bridged SILType for Swift. 2025-03-11 09:29:11 +08:00
WeZZard
35f82ba402 [SILOptimizer] Fixes the ValueDefUseWalker to handle potential unchecked_ref_cast between optional and non-optional class types.
The `unchecked_ref_cast` is designed to be able to cast between
`Optional<ClassType>` and `ClassType`. We need to handle these cases by
checking if the type is optional and adjust the path accordingly.
2025-03-10 19:17:31 +08:00
eeckstein
737b5ec924 Merge pull request #79674 from eeckstein/simplify-open-existential-metatype
Optimizer: Rework peephole optimizations to replace existential (archetypes) with concrete types
2025-03-10 08:18:52 +01:00
eeckstein
cbba008ac3 Merge pull request #79835 from eeckstein/fix-generic-specializer
GenericSpecializer: avoid an infinite loop when looking up GenericSpecializationInformation
2025-03-10 08:15:13 +01:00
Rintaro Ishizaki
accd108e4a Merge pull request #79857 from rintaro/retire-pound-diagnostics-decl
[Parse/AST] Remove PoundDiagnosticDecl
2025-03-09 21:23:16 -07:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
nate-chandler
c0ba520fac Merge pull request #79781 from nate-chandler/general-coro/20250227/1
[CoroutineAccessors] Dispatch and PtrAuth.
2025-03-07 20:08:42 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Erik Eckstein
77dab77702 Swift SIL: make isLegalFormalType available in AST.Type 2025-03-07 15:59:34 +01:00
Erik Eckstein
810064b7dc Cleanup and additions to AST and SIL Type/CanonicalType
* factor out common methods of AST Type/CanonicalType into a `TypeProperties` protocol.
* add more APIs to AST Type/CanoncialType.
* move `MetatypeRepresentation` from SIL.Type to AST.Type and implement it with a swift enum.
* let `Builder.createMetatype` get a CanonicalType as instance type, because the instance type must not be a lowered type.
2025-03-07 15:59:33 +01:00
Erik Eckstein
db03a55c79 Swift SIL: add some Builder APIs
* `createCheckedCastAddrBranch`
* `createUnconditionalCheckedCastAddr`
* `createDebugValue`
* `createWitnessMethod`
* `createInitEnumDataAddr`
2025-03-07 15:59:33 +01:00
Erik Eckstein
f7466eac78 SIL: fix bridging of SILDebugVariable
The optional C++ type was bridged to a non-optional Swift type.
The correct way is to bridged the non-optional C++ type to the non-optional Swift type.
2025-03-07 15:59:33 +01:00
Erik Eckstein
31057332ff Swift SIL: add some Instruction APIs
* getting the formal source and target types of casts
* `isFromVarDecl` and `usesMoveableValueDebugInfo` for AllocStackInst
* WitnessMethod APIs
* `TryApply.isNonAsync`
2025-03-07 15:59:33 +01:00
Erik Eckstein
48db89031a SIL: be more tolerant when a user is deleted during use-list iteration.
Check if an operand's instruction has been deleted in `UseList.next()`.
This allows to delete an instruction, which has two uses of a value, during use-list iteration.
2025-03-07 15:59:32 +01:00
Erik Eckstein
aff36b056b SIL: fix cloning of keypath instruction
Don't include type-dependent operands in the argument list of the new keypath instruction.
Also enable the assert, which catches this problem, in release builds.

Fixes a compiler crash.
2025-03-07 15:09:11 +01:00
Michael Gottesman
58ea40ba6d [sil] Add missing flag to SILDeclRef's hash and change SILDeclRef to use llvm::hash_combine instead of rolling its own hash combiner.
This is really old code from before llvm::hash_combine existed. We really
shouldn't be rolling out own hash combine when we have something that we are
consistently using from LLVM. I validated the history of this code and talked
with JoeG/DougG/others to see if there was any reason beyond not having
hash_combine for us not to use hash_combine.

The reason why I am changing this now is that I want to convert SILDeclRef to
have another additional bit and use an OptionSet. When I noticed this... my eyes
burned, so I thought I would just quickly fix it before I landed the other
change so it could be a NFC change.
2025-03-06 13:28:34 -08:00
Andrew Trick
5783b497e5 Merge pull request #79758 from atrick/addressable-deps
Support enforcement of '@'_addressable under -enable-address-dependencies
2025-03-03 23:51:56 -08:00
Meghana Gupta
cf6c4c9422 Merge pull request #79699 from meg-gupta/prboundscheck
Add support for bounds check optimization of Span and InlineArray
2025-03-03 14:32:27 -08:00
Andrew Trick
bc6200e592 SwiftCompilerSources: bridge '@'_addressable dependencies 2025-03-03 11:56:37 -08:00
Andrew Trick
d73a081fe7 Add pointer escape and dependent use tracking to InteriorLiveness
Rig TransitiveAddressWalker to keep track of enough information for passes to
correctly check for pointer escapes and dependence uses. Requires for precise
bail-outs and asserts.
2025-03-02 23:51:34 -08:00
Andrew Trick
45cac09728 Fix TransitiveAddressWalker with mark_dependence
This utility was simply ignoring the dependent value. But the
dependent value logically uses the base address. Until this is
correctly implemented, conservatively consider it a pointer-escape.
2025-03-01 22:25:42 -08:00
Meghana Gupta
9ce8bb3682 Add a new abstraction FixedStorageSemanticsCall 2025-02-28 09:50:58 -08:00
nate-chandler
30d91d39bf Merge pull request #79625 from nate-chandler/general-coro/20250212/1
[CoroutineAccessors] Use retcon.once variant.
2025-02-27 12:58:49 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Slava Pestov
541757a491 AST: Remove TypeBase::isOpenedExistential()
At one point, OpenedArchetypeType did not exist as a separate subclass
of ArchetypeType, so this method did something. Now, it's just
equivalent to calling is<> or isa<>.

I also removed a couple of asserts that were obvious no-ops as a result.
2025-02-27 09:55:36 -05:00
Andrew Trick
f29bb44d07 OwnershipUseVisitor::visitInnerBorrowUses: support dependent values
Add liveness support for dependent values: borrowed-from & mark_dependence so
they aren't reported as unknown uses.

Centralize the logic in BorrowingOperand::getScopeIntroducingUserResult
and BorrowingOperand::getDependentUserResult().
2025-02-25 23:08:55 -08:00
Andrew Trick
c3641818c6 Add MarkDependenceInst::hasScopedLifetime 2025-02-25 23:08:55 -08:00
Andrew Trick
e8af00769e Remove adjacent phis from OwnershipLiveness.
The extra complexity for traversing phis is not needed now that it handles
borrowed-from instructions. Remove the redundant logic because it complicates
the liveness algorithm and generates confusing results.
2025-02-25 23:08:54 -08:00
Andrew Trick
1cb4d50877 Fix BorrowingOperand::visitScopeEndingUses() invariants.
This API only makes sense for a scoped borrow-introducer such as:
- reborrow
- owned mark_dependence

Borrowing operands that forward guaranteed values do not have scope-ending uses.
2025-02-25 23:08:54 -08:00
Andrew Trick
6fa0b2ec98 Add BorrowedFromInst::isReborrow.
borrowed-from instructions have different ownership semantics if the are
attached to reborrows vs. guaranteed forwarding phis.
2025-02-25 23:08:54 -08:00
Andrew Trick
e78aa38204 Remove BorrowingOperand.getImplicitUses.
It is buggy/misleading because of dead-def handling. The current operand may be
re-pushed if it is a dead borrow scope.
2025-02-25 23:08:54 -08:00
Andrew Trick
b3a445fb55 Fix BorrowingOperand::getBorrowIntroducingUserResult()
To handle borrowing operands that produce a dependence value but do not create a
nested borrow scope. This includes non-reborrow borrowed-from and guaranteed
mark_dependence [nonescaping].
2025-02-25 23:08:54 -08:00
Andrew Trick
f1792d80b3 Fix BorrowingOperand.visitScopeEndingUses
Only return false if the visitor returns false. Clients were ignoring the
result.

If the BorrowingOperand does not create a borrow scope, call visitUnknownUse
instead.

Until we have complete lifetimes, to avoid breaking code that cannot handle dead
defs, consider a dead borrow scope to be an unknown use.
2025-02-25 23:08:54 -08:00
Andrew Trick
6c99017588 Minor comment cleanup and code formatting.
Extracted from the functional changes for clarity.
2025-02-25 23:08:53 -08:00
Michael Gottesman
5c15952a1b Merge pull request #79610 from gottesmm/pr-9b68c5b1bcddf8ab3088f367da16aa9d82bafe94
[gardening] Fix capitalization in define guard.
2025-02-25 13:29:00 -08:00
Michael Gottesman
15733b95c3 [gardening] Fix capitalization in define guard. 2025-02-25 08:37:23 -08:00
Usama Hameed
500187cf1e Add support for serializing debug_value instructions (#78056)
This patch adds support for serialization of debug value instructions. Enablement is currently gated behind the -experimental-serialize-debug-info flag.

Previously, debug_value instructions were lost during serialization. This made it harder to debug cross module inlined functions.
2025-02-24 20:21:15 -08:00
Erik Eckstein
9b143d876b PassManager: invalidate analysis if a pass forgot to do so.
If a pass forgot to call invalidateAnalysis but deleted some instructions, the pass-manager can fix this.

Currently following passes do not invalidate analysis when they change the SIL:
* LowerTupleAddrConstructor
* DestroyAddrHoisting
* MoveOnlyChecker
* PredictableDeadAllocationElimination

Ideally we should fix those passes. But with this addition in the pass-manager it's not strictly necessary.

Fixes a compiler crash.
2025-02-14 08:08:43 +01:00
eeckstein
de80540afe Merge pull request #79347 from kateinoigakukun/pr-8e92b88f71e902460e83c323bd92071f40e3f165
[SIL] Explicitly use `uint64_t` for `maxBitfieldID`
2025-02-14 07:13:58 +01:00
Yuta Saito
84bfaf5f7e [SIL] Explicitly use uint64_t for maxBitfieldID
The `maxBitfieldID` was defined as `size_t` and used to assert
bitfield ID values. The `currentBitfieldID` of `SILFunction` is
defined as `uint64_t`, so we should consistently use `uint64_t`
for `maxBitfieldID` as well for 32-bit platforms.
2025-02-13 02:04:54 +00:00
Erik Eckstein
57a236e671 InitializeStaticGlobals: support statically initializing globals which are or contain inline arrays
For example:

```
struct S {
  static let slab: Slab = [1, 2, 3, 4]
}
```

rdar://143005996
2025-02-12 22:37:49 +01:00
Erik Eckstein
e0b4f71af6 SIL: remove the alloc_vector instruction
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Andrew Trick
e705a6d7c3 Temporarily introduce AnyInteriorPointer operand ownership.
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
2025-02-05 16:23:02 -08:00
Joe Groff
1e37b67a96 BorrowToDestructureTransform: Fix order of operations when placing borrows around InteriorPointerOperands.
The code here determined the borrow scope of an InteriorPointerOperand use of a borrow using
`visitBaseValueScopeEndingUses`, but it does so after rewriting the operand, so the base
value would sometimes be incorrect leading to missing `end_borrows` in the rewritten code.
Fixes rdar://133333278.
2025-02-04 18:43:40 -08:00
Joe Groff
19329e3e03 SILGen: Treat read-formal-accessed lvalues as borrows.
A read access asserts that the memory location is immutable for the duration
of the access, so it can be treated as a borrow rather than a mutable lvalue.
Doing this allows the borrow formal access scope fixes from #79084 to apply
to situations where a loadable type undergoes an accessor-based access with
indirect arguments (such as for public accessors when library evolution is
enabled for the type). Fixes rdar://143334632.
2025-02-04 08:23:34 -08:00
Arnold Schwaighofer
c95c45201e Merge pull request #78996 from aschwaighofer/checked_cast_br_nightmares
SIL: Update formal source type in SimplifyRefCasts when possible
2025-02-02 08:27:01 -08:00
Arnold Schwaighofer
0fe3cf0096 SIL: Update formal source type in SimplifyRefCasts when possible
We use the formal source type do decide whether a checked_cast_br is
known to succeed/fail. If we don't update it we loose that optimization

That is:

```
  checked_cast_br AnyObject in %2 : X to X, bb1, bb2
```

Will not be simplified even though the operand and the destintation type
matches.
2025-01-29 09:07:21 -08:00
Meghana Gupta
27fc324c8c Fix AddressOwnership for unidentified access
AccessBase can have Unindentified kind where the base value maybe
invalid.

Bailout early for such accesses in ownership rauw.
2025-01-28 09:08:38 -08:00
eeckstein
95f1dfbf07 Merge pull request #78885 from eeckstein/fix-without-actually-escaping
Fix two problems with `withoutActuallyEscaping`
2025-01-27 07:59:02 +01:00
Andrew Trick
f0144ab7b1 Merge pull request #78830 from atrick/fix-lifedep-trivial-deadend
SILGenCleanup: extend to handle trivial local var scopes
2025-01-25 15:34:35 -08:00