Commit Graph

789 Commits

Author SHA1 Message Date
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
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
Erik Eckstein
3ec5d7de24 SIL: replace the is_escaping_closure instruction with destroy_not_escaped_closure
The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
2025-01-24 19:23:27 +01:00
Michael Gottesman
7ae56aab2e [sil] Add a new instruction ignored_use.
This is used for synthetic uses like _ = x that do not act as a true use but
instead only suppress unused variable warnings. This patch just adds the
instruction.

Eventually, we can use it to move the unused variable warning from Sema to SIL
slimmming the type checker down a little bit... but for now I am using it so
that other diagnostic passes can have a SIL instruction (with SIL location) so
that we can emit diagnostics on code like _ = x. Today we just do not emit
anything at all for that case so a diagnostic SIL pass would not see any
instruction that it could emit a diagnostic upon. In the next patch of this
series, I am going to add SILGen support to do that.
2025-01-22 21:12:36 -08:00
Erik Eckstein
83224b255e SIL: automatically set the reborrow flags for phi-arguments when creating an end_borrow or setting the operand of an end_borrow
This is done for all transitively incoming phi-arguments of an end_borrow operand.
2024-11-12 09:26:58 +01:00
Michael Gottesman
3c38c79f7a [region-isolation] Implement MergeIsolationRegionInst.
I am adding this instruction to express artificially that two non-Sendable
values should be part of the same region. It is meant to be used in cases where
due to unsafe code using Sendable, we stop propagating a non-Sendable dependency
that needs to be made in the same region of a use of said Sendable value. I
included an example in ./docs/SIL.rst of where this comes up with @out results
of continuations.
2024-11-01 11:25:53 -07:00
John McCall
56ec62570f Merge pull request #77308 from rjmccall/optional-isolation-check
Fix a crash when emitting isolation checks in a function with optional isolation
2024-10-31 10:50:27 -07:00
John McCall
718390a615 Add a helper function for emitting a switch_enum that breaks down an Optional. 2024-10-30 14:41:50 -07:00
Nate Chandler
0597ec5989 [SIL] BuiltinInsts have type dependent operands.
Collect all types in the substitution map which constitute
type-dependent operands and record them in the instruction's operand
list.  Fixes a bug where open_existential_metatype (e.g.) is deleted as
dead because it has no users even when the type it defines is used in a
substitution map of a builtin.
2024-10-29 21:45:25 -07:00
Michael Gottesman
0e0665bfbd [concurrency] Add support for HopToMainActorIfNeededThunk.
It is behind the experimental flag GenerateForceToMainActorThunks.
2024-10-17 13:31:39 -07:00
Michael Gottesman
561662d6cc [sil] Add a new instruction called ThunkInst.
For now this will only be used for HopToMainActorIfNeeded thunks. I am creating
this now since in the past there has only been one option for creating
thunks... to create the thunk in SILGen using SILGenThunk. This code is hard to
test and there is a lot of it. By using an instruction here we get a few benefits:

1. We decouple SILGen from needing to generate new kinds of thunks. This means
that SILGenThunk does not need to expand to handle more thunks.

2. All thunks implemented via ThunkInst will be easy to test in a decoupled way
with SIL tests.

3. Even though this stabilizes the patient, we still have many thunks in SILGen
and various parts of the compiler. Over time, we can swap to this model,
allowing us to hopefully eventually delete SILGenThunk.
2024-10-02 14:15:49 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Kavon Farvardin
274f13da9a SIL: re-downgrade assertion due to issue 2024-09-02 14:44:45 -07:00
Kavon Farvardin
9d69f2bceb Merge pull request #75382 from kavon/static-branch-prediction
Throws Prediction + HotColdSplitting
2024-08-09 15:24:22 -04:00
Kavon Farvardin
0cce602bce SIL: branch weights for try_apply's 2024-08-08 21:21:52 -04:00
Alexis Laferrière
f458c56143 Revert one line from "SILBuilder: use the new ASSERT macro in the SILBuilder"
From commit bf3b69bba8.

installedOverride refers to something protected behind an `#ifndef NDEBUG`.

rdar://132930970
2024-07-31 14:53:38 -07:00
Erik Eckstein
bf3b69bba8 SILBuilder: use the new ASSERT macro in the SILBuilder
It's important to catch assert failures in the SILBuilder also in a release build of the compiler
2024-07-31 15:31:03 +02:00
Andrew Trick
3316a58ba7 Allow move_value of trivial values.
Required for SIL level local variable scopes.
2024-07-26 08:27:31 -07:00
Nate Chandler
b150a484f2 [SIL] Add dead_end flag to dealloc_box. 2024-07-03 15:26:59 -07:00
Nate Chandler
a8cc3bfdda [SIL] Add dead_end flag to destroy_value. 2024-07-03 15:26:59 -07:00
Nate Chandler
91fe12aab4 [NFC] SIL: Typed debug_value.poisonRefs. 2024-07-03 14:53:30 -07:00
Nate Chandler
d76a8e671e [NFC] SIL: Typed destroy_value.poisonRefs.
Type the existing flag before adding another flag.
2024-07-03 14:53:30 -07:00
Meghana Gupta
79acb5ac47 Fix ownership of move-only enums in SIL 2024-06-29 22:58:45 -07:00
Nate Chandler
2a5d07522d [SIL] Add extend_lifetime instruction.
It indicates that the value's lifetime continues to at least this point.
The boundary formed by all consuming uses together with these
instructions will encompass all uses of the value.
2024-06-05 16:28:26 -07:00
Emil Pedersen
0bc6ece9db [DebugInfo] [SILGen] Always use emitDebugDescription (NFCI) 2024-05-23 14:05:13 -07:00
Erik Eckstein
941a7427d8 handle upcast instructions in statically initialized globals
This allows statically initialized multi-dimensional arrays in embedded swift.
2024-05-21 13:33:06 +02:00
Erik Eckstein
f3dafbff2f SIL: make unchecked_ref_cast buildable in a global variable initializer 2024-05-16 21:34:35 +02:00
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
95d2479889 [DebugInfo] Fix verifier crash for complex switch
An alloc_stack, just like a debug_value, should ignore location
overrides for their variable.

Fixes #73338
rdar://127348128
2024-05-07 18:51:13 -07:00
Emil Pedersen
523a769e34 [DebugInfo] [Mem2Reg] Move debug info promotion to salvageDebugInfo 2024-04-23 13:12:21 -07:00
Erik Eckstein
ac4bc89c9a SIL: add the borrowed-from instruction.
It declares from which enclosing values a guaranteed phi argument is borrowed from.
2024-04-10 13:38:10 +02:00
Anton Korobeynikov
d84847ac9d Reland Allow normal function results of @yield_once coroutines (#71645)
* Allow normal function results of @yield_once coroutines

* Address review comments

* Workaround LLVM coroutine codegen problem: it assumes that unwind path never returns.
This is not true to Swift coroutines as unwind path should end with error result.
2024-03-27 13:09:02 -07:00
Meghana Gupta
a15d5fea09 Fix ownership of move-only structs in SIL
Not doing this for enums yet because it is tripping the ownership verifier

We dont have move-only tuples yet.
2024-03-13 16:24:57 -07:00
Joe Groff
8a65c9be94 SIL: Optimizer fixes for noncopyable optional chains.
Don't attempt a SILCombine transform on `select_enum` that inserts a copy when an
enum is noncopyable. Adjust the cleanup handling for a consuming optional chain to
ensure a `destroy_value` still gets emitted on the `none` path; this shouldn't
actually matter since `none` is a trivial case, but the memory verifier isn't
that fancy during OSSA, and we can optimize it later. Fixes rdar://124426918.
2024-03-12 18:11:21 -07:00
Nate Chandler
3dbeebaa9b [SIL] Add var_decl flag to alloc_stack. 2024-03-08 22:28:22 -08:00
Nate Chandler
37d8984bea [NFC] SIL: Typed move_value's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
83bc56fd5b [NFC] SIL: Typed begin_borrow's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
7fecf6149c [NFC] SIL: Typed begin_borrow's isFixed. 2024-03-08 22:28:20 -08:00
Nate Chandler
46b08bd386 [SIL] NFC: Typed move_value's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
70d90b4b43 [NFC] SIL: Typed begin_borrow's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
401440748f [NFC] SIL: Typed alloc_box's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
7db84f25b1 [NFC] SIL: Typed move_value's isLexical. 2024-03-08 22:27:52 -08:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Nate Chandler
c6eb3112b5 [NFC] SIL: Typed alloc_stack's isLexical. 2024-03-08 21:24:39 -08:00
Nate Chandler
ec6b447b68 [NFC] SIL: Typed alloc_box's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
dfa5c9814b [NFC] SIL: Typed alloc_stack's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
11dd0e4aa6 [NFC] SIL: Typed debug_value's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
e10d595328 [NFC] SIL: Typed alloc_box's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
611511a71f [NFC] SIL: Typed alloc_stack's wasMoved.
Help avoid errors with boolean flags by introducing
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00