Commit Graph

571 Commits

Author SHA1 Message Date
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
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
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05: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
Erik Eckstein
895eb2a5c6 SILCloner: fix creating a wrong type for cloned witness_method instructions
The type needs to be mapped.
2024-10-07 09:00:31 +02: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
45d7ea39a5 Merge pull request #75518 from Azoy/integer-generics
Implement Value generics
2024-09-05 15:33:46 -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
Slava Pestov
b1e0e776b4 AST: Simplify SubstitutionMap::lookupConformance() 2024-09-04 14:57:38 -04:00
Slava Pestov
c47f352df7 AST: Use new form of getOpenedExistentialSignature() in GenericEnvironment::forOpenedExistential() 2024-09-04 10:42:18 -04:00
Slava Pestov
35488edefb SIL: Use getDefinedOpenedArchetype() to simplify SILCloner 2024-09-04 00:00:35 -04:00
Slava Pestov
e3ff6f0697 AST: Fiddle with GenericEnvironment::forOpenedExistential() again 2024-09-03 17:31:26 -04:00
Slava Pestov
e79763b590 AST: Factor out mapLocalArchetypesOutOfContext() utility function 2024-08-30 15:24:00 -04:00
Slava Pestov
cf784f980e AST: Remove SubstFlags::AllowLoweredTypes 2024-08-23 13:14:05 -04:00
Slava Pestov
da4d076f02 AST: Introduce SubstFlags::SubstitutePrimaryArchetypes 2024-08-22 18:41:14 -04:00
Slava Pestov
63028be348 SILCloner: Redo local archetype remapping 2024-08-22 17:17:53 -04:00
Slava Pestov
39b4bda1dc AST: Introduce SubstFlags::SubstituteLocalArchetypes 2024-08-21 14:23:37 -04:00
Slava Pestov
ae77d6f0c1 AST: Replace one-off predicates with SubstitutionMap::getRecursiveProperties() 2024-08-21 13:19:10 -04:00
Slava Pestov
5577f27661 AST: Opened existential environments store outer substitutions 2024-08-20 16:54:51 -04:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Slava Pestov
c321b337ba SIL: Fix crash with missing existential Sendable conformance
If a protocol does not inherit Sendable, we still say that the
existential type is Sendable in Swift 5 mode. Make sure this
doesn't crash the SIL specializer.

Fixes https://github.com/swiftlang/swift/issues/75728
2024-08-08 16:17:16 -04:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04: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
Erik Eckstein
d80813ee3b SIL: update borrowed-from instructions when cloning a basic block
Cloning blocks might split CFG edges which can "convert" terminator result arguments to phi-arguments.
In this case a borrowed-from instruction must be inserted.

Fixes a SIL verifier crash caused by SimplifyCFG's jump threading.
rdar://129187525
2024-06-12 12:56:34 +02: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
Slava Pestov
8af57e9094 SIL: Copy opaque archetype substitution logic into SILCloner 2024-05-21 13:52:58 -04:00
Slava Pestov
093f255bdc SIL: Allow SILCloner to work with a substitution map 2024-05-17 15:16:11 -04:00
Slava Pestov
388a2d7d35 SIL: Add some debugging code 2024-05-15 17:39:00 -04:00
Slava Pestov
62630365c2 SIL: Sink local archetype substitution into remapConformance() 2024-05-15 17:39:00 -04:00
Slava Pestov
a356b10929 SIL: Sink local archetype substitution into remapType() 2024-05-15 17:39:00 -04:00
Slava Pestov
0a0b17a660 SIL: Sink local archetype substitution into remapASTType() 2024-05-15 17:39:00 -04:00
Slava Pestov
3b5846d458 SIL: Sink local archetype substitution into remapSubstitutionMap() 2024-05-15 17:39:00 -04:00
Slava Pestov
1cdb654ba2 SIL: Tidy up SILCloner 2024-05-14 13:48:08 -04:00
Adrian Prantl
6357d12cfc Merge pull request #73009 from Snowy1803/debuginfo-small-fixes
[Debuginfo] Small fixes
2024-04-17 00:03:53 +02:00
Emil Pedersen
5512df5837 [SILCloner] Remap debug variable type and scope at the same time (NFC) 2024-04-16 10:28:13 -07:00
John McCall
82d9e4cb59 Fix a crash when serializing variadic generic tuple code under -wmo
It seems really unfortunate that we use SILCloner to, basically,
implement a recursive visitor of the types used in a SIL function,
but apparently it's what we do.

Fixes #72117.
2024-04-11 17:22:10 -04: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
Slava Pestov
5cf05ecfcf Revert "SILCloner: allow builtin conformances"
This reverts commit abae144c92.
2024-04-01 14:19:01 -04:00
Kavon Farvardin
abae144c92 SILCloner: allow builtin conformances
When cloning SIL, it's OK for conformances to Copyable or Escapable to
be carried-over as a builtin conformance, rather than an abstract
conformance.

This is a workaround for a bug introduced in
`6cd5468cceacc1d600c7dafdd4debc6740d1dfd6`.

resolves rdar://125460667
2024-03-28 15:45:11 -07: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
Emil Pedersen
3c1ef77b23 [DebugInfo] Fix specialization of debug variable types 2024-03-20 15:35:52 -07:00
Nate Chandler
7884892d08 [SIL] Fix alloc_box cloning.
Previously, all the flags were dropped upon cloning.
2024-03-08 22:28:22 -08:00
Nate Chandler
3dbeebaa9b [SIL] Add var_decl flag to alloc_stack. 2024-03-08 22:28:22 -08:00
Nate Chandler
ec6b447b68 [NFC] SIL: Typed alloc_box's hasDynamicLifetime. 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
5ccec0e31c [NFC] SIL: Shortened member name.
Renamed "getUsesMoveableValueDebugInfo" to "usesMoveableValueDebugInfo".
Clarifies the predicate from "does the receiver have the
usesMoveableValueDebugInfo field set?" to "does the receiver use moveable
value debug info?".
2024-03-08 21:24:38 -08:00