Commit Graph

1604 Commits

Author SHA1 Message Date
Erik Eckstein
d28384dbd7 SILGen: use vector_base_addr in InlineArray literals 2025-05-12 19:25:12 +02:00
Alejandro Alonso
02d9779ba3 Merge pull request #81184 from Azoy/no-more-is-array-type
[AST] Rename isArrayType and split the InlineArray portion
2025-05-08 20:52:51 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Slava Pestov
cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
Nate Chandler
7697a49ee9 [CoroutineAccessors] Only reference when available
Don't bind references to storage to use (new ABI) coroutine accessors
unless they're guaranteed to be available.  For example, when building
against a resilient module that has coroutine accessors, they can only
be used if the deployment target is >= the version of Swift that
includes the feature.

rdar://148783895
2025-04-15 21:13:57 -07:00
Joe Groff
7ce06dde2c Merge pull request #80773 from jckarter/trivial-copy-operator
SILGen: Emit `copy x` on a trivial value as a trivial copy.
2025-04-15 09:47:13 -07:00
Joe Groff
8dac2b1566 SILGen: Emit copy x on a trivial value as a trivial copy.
Avoids an assertion failure emitting an `explicit_copy_value` on the trivial
value, which is unsupported. This allows `copy x` to compile, albeit with
no effect (which is not ideal, but also not a regression, since no-implicit-copy
controls still don't fully work on trivial values). Fixes #80573 and rdar://148712387.
2025-04-11 17:51:43 -07:00
Pavel Yaskevich
9da457d129 [Sema/SILGen] NFC: Remove all mentions of @execution from comments 2025-04-11 15:59:25 -07:00
Slava Pestov
ea05708716 AST: Eliminate GenericEnvironment::mapConformanceRefIntoContext() 2025-04-03 17:35:34 -04:00
Slava Pestov
a209ff8869 AST: Remove origType parameter from ProtocolConformanceRef::subst() 2025-04-03 17:35:33 -04:00
Slava Pestov
8b1514cfd7 AST: Remove origType parameter from ProtocolConformanceRef::getAssociatedConformance() 2025-04-03 17:35:32 -04:00
Michael Gottesman
f245389bb3 [concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
Specifically:

1. I made it so that thunks from caller -> concurrent properly ignore the
isolated parameter of the thunk when calling the concurrent function.

rdar://148112362

2. I made it so that thunks from concurrent -> caller properly create a
Optional<any Actor>.none and pass that into the caller function.

rdar://148112384

3. I made it so that in cases where we are assigning an @Sendable caller to a
non-sendable caller variable, we allow for the conversion as long as the
parameters/results are sendable as well.

rdar://148112532

4. I made it so that when we generate a thunk from @execution(caller) ->
@GlobalActor, we mangle in @GlobalActor into the thunk.

rdar://148112569

5. I discovered that due to the way we handle function conversion expr/decl ref
expr, we were emitted two thunks when we assigned a global @caller function to a
local @caller variable. The result is that we would first cast from @caller ->
@concurrent and then back to @caller. The result of this would be that the
@caller function would always be called on the global queue.

rdar://148112646

I also added a bunch of basic tests as well that showed that this behavior was
broken.
2025-03-30 20:00:05 -07:00
Slava Pestov
5a684c3a29 SILGen: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Alejandro Alonso
241ffafe7f Merge pull request #80245 from Azoy/ia-literal-closure
[SILGen] Use the opaque element type for address in InlineArray literal
2025-03-24 23:21:06 -07:00
Alejandro Alonso
bc6c88bfb1 Use the opaque element type for address in InlineArray literal 2025-03-24 10:35:14 -07:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Amritpan Kaur
807c323159 [SILGenExpr] Lower initializers. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
45a7b45ad9 [SILGen] Lower unapplied methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
4479996d7b [NFC] Refactor method thunk handling for reuse. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
60e03a85d9 [SILGen] Lower applied keypath methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
ae86b0e96d [NFC] Refactor getter/setter logic for reuse. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
e7e354d989 [NFC] Generalize subscript code for methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
2583da94b2 [NFC] Generalize subscript index handling. 2025-03-19 08:53:18 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Amritpan Kaur
8f71f5c780 [NFC] Rename property to member to generalize
for both properties and method members.
2025-03-19 08:53:18 -07:00
Alejandro Alonso
8b3499d90e Fix empty inline array literals 2025-03-13 09:53:28 -07:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01: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
Shubham Sandeep Rastogi
52a5ed8646 Pass correct SubExpr as source location when emitting Load of LValue.
When emitting an LValue of a LoadExpr during SILGen, the Expression
passed as a SILLocation for the LValue was the parent LoadExpr instead
of the SubExpr that contains the LValue for the load. This leads to
the SILLocation to be marked as implicit, because a LoadExpr is always
an implicit expression.

An implicit SILLocation is not emitted when doing IRGen as it is
considered to be hidden from debug info and thus we lose the debug
location for the LValue of a LoadExpr.

This patch fixes this issue.
2025-02-21 09:16:30 -08:00
Rintaro Ishizaki
73164a0ffd Merge pull request #79353 from rintaro/astgen-magic-ident-literal
[ASTGen] Generate MagicIdentifierLiteralExpr
2025-02-13 06:25:09 -08:00
Rintaro Ishizaki
563ddc47e2 [AST] Eliminate 'SYNTAX_KIND' from MagicIdentifierKinds.def
Nothing is using it.
2025-02-12 23:19:34 -08:00
Guillaume Lessard
c7af9a701b Merge pull request #79294 from Azoy/bye-bye-slab
[stdlib] Rename Slab to InlineArray
2025-02-12 12:03:25 -08:00
Slava Pestov
68bdfa81e3 SILGen: Fix verifier error when forming keypath to subscript with resilient index type
emitKeyPathSubscriptOperands() uses the ArgEmitter to collect
index arguments, which uses ResilienceExpansion::Minimal when
lowering parameter types.

For this reason, lowerKeyPathSubscriptIndexTypes() should also
use ResilienceExpansion::Minimal when lowering parameter types.

Otherwise, we crash in the SIL verifier due to a loadable vs
address-only mismatch, if the index type is resilient.

Fixes rdar://problem/144654366.
Fixes https://github.com/swiftlang/swift/issues/79304.
2025-02-11 22:14:23 -05:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Amritpan Kaur
451737b48e [SILGen] Look through base metatype to find substitutions. 2025-02-09 10:19:44 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00: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
Erik Eckstein
42fef1fb68 SILGen: let withoutActuallyEscaping also catch an escaping closure in the throwing case
withoutActuallyEscaping checks that the passed closure has not beed escaped by ensuring that its reference count is exactly 1 at the end of the code block.
So far this was only done in the regular return case. But if the code block throws, the check was not done.

Fixes an undetected undefined behavior.
2025-01-24 18:57:40 +01:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Alejandro Alonso
61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00
Pavel Yaskevich
c4e4d4d6da [SIGen] UnsafeCastExpr: Use forwarding cast instead of bitcast
Forwarding cast handles ownership correctly and doesn't disable
optimizations unlike bitcast.
2024-12-11 17:19:20 -08:00
Pavel Yaskevich
5e08f7e257 [CSApply/SILGen] Implement any Sendable to Any erasure for generic arguments
In non-strict concurrency mode when `@preconcurrency` declarations
are involved `any Sendable` should be treated as `Any` in generic
argument positions to support passing types that (partially) adopted
concurrency annotations to types that haven't yet done so.
2024-12-11 17:19:14 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Akira Hatanaka
f73c2e51bd Revert "[SILGen] Fix the type of closure thunks that are passed const reference structs (#76903)" (#77309)
This reverts commit 9c44b79189.

The commit caused swift's deserialization code to crash.

rdar://138726860
2024-10-31 15:16:00 -07:00
Akira Hatanaka
9c44b79189 [SILGen] Fix the type of closure thunks that are passed const reference structs (#76903)
The thunk's parameter needs the @in_guaranteed convention if it's a
const reference parameter. However, that convention wasn't being used
because clang importer was removing the const reference from the
type and SILGen was computing the type of the parameter based on the
type without const reference.

This commit fixes the bug by passing the clang function type to
SILDeclRef so that it can be used to compute the correct thunk type.

This fixes a crash when a closure is passed to a C function taking a
pointer to a function that has a const reference struct parameter.

This recommits e074426 with fixes to
serialization/deserialization of function types. The fixes prevent clang
types of functions from being dropped during serialization.

rdar://131321096
2024-10-08 23:44:49 -07:00
John McCall
af8115ffa3 Hop to the current isolation properly in delegating async actor initializers.
This requires two major changes.

The first is that we need to teach SILGen that the isolation of an initializer
is essentially dynamic (as far as SILGen is concerned) --- that it needs to emit
code in order to get the isolation reference.  To make this work, I needed to
refactor how we store the expected executor of a function so that it's not
always a constant value; instead, we'll need to emit code that DI will lower
properly.  Fortunately, I can largely build on top of the work that Doug previously
did to support #isolation in these functions.  The SIL we emit here around delegating
initializer calls is not ideal --- the breadcrumb hop ends up jumping to the
generic executor, and then DI actually emits the hop to the actor.  This is a little
silly, but it's hard to eliminate without special-casing the self-rebinding, which
honestly we should consider rather than the weirdly global handling of that in
SILGen today.  The optimizer should eliminate this hop pretty reliably, at least.

The second is that we need to teach DI to handle the pattern of code we get in
delegating initializers, where the builtin actually has to be passed the self var
rather than a class reference.  This is because we don't *have* a class reference
that's consistently correct in these cases.  This ended up being a fairly
straightforward generalization.

I also taught the hop_to_executor optimizer to skip over the initialization of
the default-actor header; there are a lot of simple cases where we still do emit
the prologue generic-executor hop, but at least the most trivial case is handled.
To do this better, we'd need to teach this bit of the optimizer that the properties
of self can be stored to in an initializer prior to the object having escaped, and
we don't have that information easily at hand, I think.

Fixes rdar://87485045.
2024-10-04 22:23:00 -04:00