Commit Graph

9293 Commits

Author SHA1 Message Date
Emil Pedersen
0be63d0422 [DebugInfo] Return complete variable info from getVarInfo by default
getVarInfo() now always returns a variable with a location and scope.
To opt out of this change, getVarInfo(false) returns an incomplete variable.
This can be used to work around bugs, but should only really be used for
printing.

The complete var info will also contain the type, except for debug_values,
as its type depends on another instruction, which may be inconsistent if
called mid-pass.

All locations in debug variables are now also stripped of flags, to avoid
issues when comparing or hashing debug variables.
2024-05-10 16:12:56 -07:00
Emil Pedersen
ac865eb2f9 [SILVerifier] Verify that debug variable types match the SSA type 2024-05-10 16:12:56 -07:00
Michael Gottesman
085f3d745e [region-isolation] Return the old way of printing ActorIsolation for use when printing SIL instructions. 2024-05-10 15:59:25 -07:00
Michael Gottesman
9bfb3b7ee7 [region-isolation] Some small gardening updates in preparation for the next commit.
Specifically, I added a few helper methods and improved the logging printing.
This all makes the next commit a more focused commit.
2024-05-10 15:33:44 -07:00
nate-chandler
e74cfb02ae Merge pull request #73386 from nate-chandler/lifetime-completion/20240501/2
[LifetimeCompletion] Require boundary to be specified.
2024-05-10 07:18:22 -07:00
nate-chandler
1b848aca09 Merge pull request #73560 from nate-chandler/gardening/20240509/1
[Gardening] SIL: Verifier messages use "lifetime".
2024-05-09 23:13:07 -07:00
Nate Chandler
bd9f9eae91 [Gardening] SIL: Verifier messages use "lifetime".
Uses aren't life ending.
2024-05-09 17:50:29 -07:00
Egor Zhdan
0971654de2 Merge pull request #73513 from apple/egorzhdan/const-ref-bool-crash
[cxx-interop] Do not crash when passing `Bool` as `const T&` parameter
2024-05-09 18:44:37 +01:00
Joe Groff
2d61e3d26b Merge pull request #73531 from jckarter/forwarding-force-unwrap
SILGen: Treat Optional `x!` force unwrapping as a forwarding operation.
2024-05-09 08:35:29 -07:00
Egor Zhdan
5b5ffde79e [cxx-interop] Do not crash when passing Bool as const T& parameter
The type bridging logic assumed that if a value of type `Swift.Bool` is passed to a Clang function as an argument, then the type of the parameter must be a Clang built-in type (usually `_Bool`). This is not always correct. For instance, the type might be a templated const reference.

rdar://125508505
2024-05-09 15:28:33 +01:00
Stephen Canon
396b055369 Implement Builtin.freeze for integer and integer-vector types. (#73519)
* Implement Builtin.freeze for integer and integer-vector types.

https://llvm.org/docs/LangRef.html#freeze-instruction

> If the argument is undef or poison, ‘freeze’ returns an arbitrary, but fixed, value of type ‘ty’. Otherwise, this instruction is a no-op and returns the input argument. All uses of a value returned by the same ‘freeze’ instruction are guaranteed to always observe the same value, while different ‘freeze’ instructions may yield different values.

It's most importation for integer and integer-vector types because floating-point results are generally not poison (except in the case of conversion from poison integer values).
However, we might want to implement this for other types as well in the future.

* Make builtin.freeze TrivialUse

Also fix filecheck patterns for its test to work with asserts build.
2024-05-09 06:41:02 -04:00
Nate Chandler
632406762c [LifetimeCompletion] Add availability_with_leaks.
The new boundary allows for invalid OSSA where values are not consumed
on paths leading to blocks that exit the function normally.  In such
cases, the value is allowed to continue leaking as before.
2024-05-08 17:15:15 -07:00
Nate Chandler
518de7c6b1 [LifetimeCompletion] Require boundary spec.
Don't default to one boundary or another based on whether the value
being completed is lexical.
2024-05-08 17:15:15 -07:00
Nate Chandler
c11a2cef91 [NFC] LifetimeCompletion: Fix switch order.
Match the declaration order.
2024-05-08 17:15:14 -07:00
Nate Chandler
de5d2ece86 [NFC] LifetimeCompletion: Improve lambda name.
This lambda has to do with availability or the lack thereof but
unreachable instructions are of interest in this context so using the
wrong name confuses things unnecessarily.
2024-05-08 17:15:14 -07:00
Nate Chandler
a0b8324eb3 [Test] Used underscores in test name.
Makes it easier to search for since editors will see it as a single
name.
2024-05-08 17:15:14 -07:00
Ellie Shin
0f606e76cb Merge pull request #73478 from apple/elsh/pcmo-res
Support generating loadable types in serialized function when package-cmo is enabled.
2024-05-08 16:08:13 -07:00
Adrian Prantl
9a2e245678 Merge pull request #73504 from Snowy1803/rdar127348128
[DebugInfo] Fix verifier crash for complex switch
2024-05-08 16:06:00 -07:00
Joe Groff
82e566a23a SILGen: Treat Optional x! force unwrapping as a forwarding operation.
Like `?` or property access, `x!` can be borrowing, consuming, or mutated
through depending on the use site and the ownership of the base value.
Alter SILGen to emit `x!` as a borrowing operation when the result is only
used as a borrow. Fix the move-only checker not to treat the unreachable
branch as a dead path for values and try to destroy the value unnecessarily
and possibly out-of-order with cleanups on the value. Fixes rdar://127459955.
2024-05-08 15:35:07 -07:00
Ellie Shin
9b28969e2d To support serializing functions containing loadable types in a resiliently built
module when package serialization is enabled, return maximal resilience expansion
in SILFunction::getResilienceExpansion(). This allows aggregate types to be generated
as loadable SIL types which otherwise are address-only in a serialized function.
During type lowering, opaque flag setting is also skipped if package serialization
is enabled.

Resolves rdar://127400743
2024-05-08 05:01:25 -07:00
Emil Pedersen
6136183c33 [DebugInfo] Fix loss of VarDecl in debug values for salvaged stores
When a store is salvaged, its debug_value will have two locations:
the location of the store, attached to the debug_value instruction,
and the location of the variable, attached to the SILDebugVariable.

The getDecl function was using the location of the store, instead
of the location of the variable, and so was returning nullptr.
2024-05-07 14:34:18 -07:00
Emil Pedersen
4bc672e7c1 [DebugInfo] Deduplicate location and scope in debug variables (NFC) 2024-05-07 13:58:57 -07:00
nate-chandler
e805679c76 Merge pull request #73460 from nate-chandler/gh73252
[Test] Reenable SIL unit tests on windows.
2024-05-07 10:15:11 -07:00
Nate Chandler
c84e196b16 [Test] Reenable SIL unit tests on windows.
Use `fflush(stdout)` from C++.

Issue 73252.
2024-05-06 12:20:16 -07:00
Erik Eckstein
b636da1716 SILVerifier: be more tolerant if errors were detected in diagnostic passes
SIL cannot be assumed to be 100% valid if errors were detected in diagnostic passes. For example in DefiniteInitialization.

Fixes some false verifier errors in case -sil-verify-all is used.

rdar://127519229
rdar://127518886
2024-05-06 16:06:36 +02:00
nate-chandler
bcd08c0c9a Merge pull request #73235 from nate-chandler/bitwise-copyable/enable
[BitwiseCopyable] Promote to feature.
2024-05-04 10:16:40 -07:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -07:00
Slava Pestov
625436af05 Merge pull request #73393 from slavapestov/pack-expansion-closures-part-3
SIL type lowering support for closures that capture pack element archetypes
2024-05-02 19:43:24 -04:00
Emil Pedersen
bf58b030c5 Merge pull request #73387 from Snowy1803/allocbox-fix
[DebugInfo] Fix loss of variables at -Onone
2024-05-02 12:39:17 -07:00
Slava Pestov
fa89c52556 SIL: Introduce TypeConverter::getForwardingSubstitutionsForLowering() 2024-05-02 14:28:30 -04:00
Slava Pestov
fa2cd6cbcc SIL: Support element archetypes inside lowerCaptureContextParameters() 2024-05-02 13:40:54 -04:00
Slava Pestov
1cad5f9350 SIL: Plumb pack element captures through type lowering 2024-05-02 13:40:54 -04:00
Slava Pestov
70fb18e799 SIL: Rename misleading getFunctionInterfaceTypeWithCaptures() 2024-05-02 13:40:54 -04:00
nate-chandler
d5aafbcdad Merge pull request #73368 from nate-chandler/lifetime-completion/20240501/1
[NFC] LifetimeCompletion: Clarified API and documentation.
2024-05-01 18:02:46 -07:00
Slava Pestov
9e13db09e0 SIL: buildThunkType() uses (new) LocalRequirementArchetypeCollector 2024-05-01 15:35:24 -04:00
Nate Chandler
2ca995177c [NFC] LifetimeCompletion: Lift default a level. 2024-05-01 08:57:01 -07:00
Nate Chandler
5383df755a [NFC] LifetimeCompletion: Clarify modes.
Completion is done along a boundary, either the availability or the
liveness boundary.  Represent which with a type.  Update docs and names.
2024-05-01 08:57:01 -07:00
Nate Chandler
fcd25ead54 [NFC] LifetimeCompletion: Clarify doc and code. 2024-05-01 08:57:00 -07:00
Nate Chandler
9c16318ad9 [NFC] LifetimeCompletion: Simplified enum wrapper. 2024-05-01 08:57:00 -07:00
Slava Pestov
865b155f2e SIL: Thunks that capture local environments must also capture the primary environment
I suspect there are latent bugs here with generic-class-constrained existentials,
same-element requirements involving packs, etc. We can't assume that the
local archetypes don't have "hidden" dependencies on the outer parameters
that are not encoded in the thunk's interface type.
2024-04-30 22:45:41 -04:00
Slava Pestov
97d95218f8 AST: Record captured generic environments in CaptureInfo 2024-04-30 21:38:15 -04:00
Emil Pedersen
f6232a937d [DebugInfo] Fix wrong scope being used in AllocBoxToStack 2024-04-30 16:29:49 -07:00
Akira Hatanaka
428fe21855 [SILGen] Fix a bug where the wrong convention was being used for computing the type of a closure thunk (#73299)
The ObjC selector family convention was being used instead of the C
function type convention.

rdar://127090209
2024-04-29 18:03:59 -07:00
nate-chandler
30fa15a01b Merge pull request #73278 from nate-chandler/lifetime-completion/20240425/2
[SIL] Only verify ownership when not disabled.
2024-04-26 07:00:46 -07:00
Nate Chandler
640e3986f9 [SIL] Only verify ownership when not disabled.
The option -disable-sil-ownership-verifier should almost never be used.
But if it is, it should result in ownership verification being disabled,
even when done via direct calls to `SILFunction::verifyOwnership`.

There are still a couple of test cases that use
-disable-sil-ownership-verifier.
2024-04-25 18:06:29 -07:00
Nate Chandler
29d046fa42 [SIL] Add BorrowedValueKind::BeginApplyToken.
The token is a guaranteed value introduced by the begin_apply and
consumed by its end_apply, abort_apply, and end_borrow users.
2024-04-25 17:03:43 -07:00
Nate Chandler
5307ac666e [SIL] Permit end_borrow(begin_apply). 2024-04-25 17:03:41 -07:00
Nate Chandler
121b2faccc [NFC] SIL: Add ValueBase::isBeginApplyToken.
Forwards to the member function of the same name on
MultipleValueInstructionResult.
2024-04-25 17:03:11 -07:00
Emil Pedersen
a31d15c438 Merge pull request #72964 from Snowy1803/mem2reg-salvage-store
[DebugInfo] Salvage all stores
2024-04-25 16:52:37 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00