Commit Graph

132 Commits

Author SHA1 Message Date
Becca Royal-Gordon
aac6f64051 Make inlinability non-ABI for @abi
Inlinability doesn’t affect the mangling except in function specializations, which are applied after the fact and should never mangle in information from an ABI-only decl. That means we can simply ban these from `@abi` instead of inferring them.

Also adds some assertions to help double-check that SIL never tries to directly mangle or retrieve inlinability info from an ABI-only decl.
2025-04-18 14:50:01 -07:00
Nate Chandler
056fbc44c9 [CoroutineAccessors] Control ABI via flag. 2025-04-10 07:41:37 -07:00
Becca Royal-Gordon
5bb6245a5a [NFC] Check that SILGen doesn’t use ABI-only decls
Adds assertions in various places where properties that can vary between ABI-only decls and their counterparts—particularly function and parameter attributes—are handled in SILGen, ensuring that we don’t accidentally end up processing ABI-only decls there.
2025-03-26 10:47:13 -07:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Allan Shortlidge
95cc7319a1 SIL: Revert public linkage for @_silgen_name forward declarations.
It turns out that the stdlib build depends on `internal` functions with
`@_silgen_name` getting hidden linkage in some configurations. Instead of
messing with the linkage computation, just fix the `stdlib/Error.swift` test by
making `setWillThrowHandler` `public` to give it the right linkage.

Resolves rdar://141590619.
2024-12-17 08:35:01 -08:00
Allan Shortlidge
87d625ecdc SIL: Always give @_silgen_name forward declarations public linkage.
When `@_silgen_name` is applied to a function with no body, it is a forward
declaration. It therefore must be treated as an external (public) declaration
regardless of the access level it was given in source.

Resolves rdar://141436934.
2024-12-13 16:48:18 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Allan Shortlidge
a4057551ad SILGen: Avoid attempting to profile any ClangImporter synthesized function.
ClangImporter synthesized declarations inherently do not have user written
code. Unfortunately, despite that they are not always marked implicit as they
should be. This was causing a crash when attempting to generate profile
coverage maps for synthesized constructors for imported structs.

I tried marking the constructors implicit, but that had too many knock-on
effects in tests. This more targeted fix unblocks compatibility suite testing
without trying to grapple with the implications of that more fundamental fix.

Resolves rdar://139486938.
2024-11-11 16:28:02 -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
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
Slava Pestov
9632979879 Revert "[SILGen] Fix the type of closure thunks that are passed const referen…"
This reverts commit e074426058.
2024-09-29 22:32:04 -04:00
Akira Hatanaka
e074426058 [SILGen] Fix the type of closure thunks that are passed const reference structs (#75491)
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.

rdar://131321096
2024-09-27 07:04:47 -07:00
Kuba Mracek
4c33af9ea2 [embedded] Move default arg logic from postEmitFunction to SILDeclRef::isTransparent 2024-09-25 12:57:47 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Augusto Noronha
ae98212c1a Eagerly emit getters at Onone.
Force SILGen to also eagerly emit getters when compiling at Onone.
The reason for this is that getters (even not user-written ones,
generated by result builders) can, and are often called by users
debugging swift programs, and should be available for that reason.

rdar://133329303
2024-08-13 14:53:41 -07:00
Konrad `ktoso` Malawski
eb675c222e [Distributed] Correct tbd handling for distributed thunks (#74935) 2024-07-26 16:52:18 +09:00
Becca Royal-Gordon
9cffd4528d Fix objcImpl SILGen crash with initial value
The initial value expressions of stored properties in objcImpl classes were being incorrectly marked as serializable. As a result, the compiler would crash with a SIL verification failure if one of them called a non-public function or initializer.

Fix this problem by not marking these initial value expression functions as serializable. Code in other modules should not call them anyway, since they think of the class as a pure ObjC class.

Fixes rdar://114874429.
2024-07-23 16:17:30 -07:00
Mykola Pokhylets
816d62c972 Merge remote-tracking branch 'upstream/main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/SILGen/SILGenDestructor.cpp
#	test/Concurrency/flow_isolation.swift
#	test/abi/macOS/arm64/concurrency.swift
#	test/abi/macOS/x86_64/concurrency.swift
2024-07-11 13:11:59 +02:00
Mykola Pokhylets
d7248e3acf Fixed linkage logic for isolated deallocating deinit 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
d4e449b62d SILGen for isolated deinit 2024-07-11 13:09:05 +02:00
Mykola Pokhylets
b189495518 Introduced isolated deinit as a SIL entity 2024-07-11 13:09:05 +02:00
Michael Gottesman
f781ad366d [sending] Compensate in SILGen for a typechecker bug where we do not properly mark actor isolated async closures passed to an inheritActorContext argument as being Sendable.
The reason why I am fixing this is that otherwise, we get a warning when one
creates an actor isolated closure and pass it into a task, e.x.:

```swift
@MainActor func test() {
  // We would get a warning on the closure below saying that we are sending
  // a closure that is MainActor isolated.
  Task {
    ...
  }
}
```
2024-06-21 02:24:03 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Ellie Shin
0a734c2a62 [PackageCMO] Global var and accessor linkage should be kept private/hidden in SILGen.
This PR contains changes that ensure the following:
* Global accessor linkage is kept hidden if its decl is resilient.
  - LinkageLimit::Never is returned for Global Accessor if its decl is resilient.
  - Since it's kept hidden, the use site should not expect a call to a global accessor
    if the static var decl being accessed is resilient. The bypassing resilience logic
    in AbstractStorageDecl::isResilient(accessingModule, decl) has been removed; to be
    addressed in Package CMO optimization pass.
* sil_global linkage is kept private if its decl is resilient.

Resolves rdar://129829925
2024-06-14 01:34:34 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ellie Shin
6216ec648f Merge pull request #73902 from apple/elsh/pkg-cmo-inline
[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions
2024-06-04 11:39:19 -07:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00
Ellie Shin
4ecfc96578 [SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions during SIL
inlining, generic/closure specialization, and devirtualization optimization passes.

SILFunction::canBeInlinedIntoCaller now exlicitly requires a caller's SerializedKind_t arg.
isAnySerialized() is added as a convenience function that checks if [serialized] or [serialized_for_pkg].

Resolves rdar://128704752
2024-05-27 23:05:56 -07:00
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00
Ellie Shin
c0720d5fb3 Merge pull request #73686 from apple/elsh/ir-global-accessor
Fix global accessor and class linker errors in package.
2024-05-21 22:59:10 -07:00
Ellie Shin
063d159d1b Rename isFragile() as isStrictlyResilient() in var decl.
Add isStrictlyResilient() to nominal type and module decl.
2024-05-21 18:25:10 -07:00
Ellie Shin
80855c872b Fix global accessor and class linker errors.
Add global accessors to symbol list if VarDecl is fragile, i.e.
is non-resilient or its defining module allows non-resilient
access.

Don't set the class decl to hidden if it's in a package resilience
domain; even though its defining module is built resilently, the
class symbol should be visible across modules if they are in the
same package with resilience-bypass optimization. In such case,
treat its SubclassScope to Internal.

Resolves rdar://127321129
2024-05-20 14:39:37 -07:00
Arnold Schwaighofer
09a9ba47e7 SIL: Ignore AEIC on package declaration inside declarations without effective public access
Quoting Slava:

"The AST-level access is allowed to be 'more public'. I honestly don't
know why, but it's always worked this way and the 'lowered' access
levels must always intersect the access levels of the parents but with
@uic, @aeic and @inlinable, that means just ignoring those attributes if
some enclosing context is not @uic"

rdar://128270848
2024-05-17 08:36:54 -07:00
Ellie Shin
e632c5ec96 -Add package-cmo check to bypassResilienceInPackage method.
-Fix SILDeclRef getLinkageLimit() for GlobalAccessor to return
Limit::None if bypassResilienceInPackage is enabled.
2024-05-15 16:25:16 -07:00
Michael Gottesman
acca7353db [transferring] Make async let take a transferring result if its result is non-Sendable.
Some notes:

1. If the result is non-Sendable and we didn't infer something that is
transferring, we still emit the current sema error that says that one cannot
assign a non-Sendable value to an async let.

2. When region isolation is enabled, but transferring args and results are
disabled, we leave the async let semantics alone. This means that the async let
closure is still @Sendable and one cannot pass in non-Sendable values to it.
2024-03-13 15:30:54 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Ellie Shin
72a7760027 Support package SIL linkage.
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.

Resolves rdar://121409846
2024-02-06 01:23:14 -08:00
Doug Gregor
d19f082665 Extend @_silgen_name to apply to allocating initializers, too
This enables its use on enum and struct initializers.
2024-01-13 06:29:27 -08:00
Egor Zhdan
494474b021 [cxx-interop] Support C++ default arguments
This allows calling a C++ function with default arguments from Swift without having to explicitly specify the values of all arguments.

rdar://103975014
2024-01-10 16:37:42 +00:00
Becca Royal-Gordon
85ea884a64 Make @_cdecl @implementation support __asm__
When @_objcImplementation is used to implement a C function marked with __asm__, take the attribute into account when mangling SIL references.

In theory this change should also make `clang::OverloadableAttr` functions mangle correctly, but in practice the matching logic for @_cdecl @_objcImplementation doesn’t currently support overloadable functions (and it’s not wise to try anyway, since clang doesn’t promise that their ABI won’t change).

Fixes rdar://120503717.
2024-01-04 18:25:07 -08:00
Allan Shortlidge
d16d9799f2 SIL: Allow package decls to be serialized when appropriate.
https://github.com/apple/swift/pull/70100 prohibited `package` declarations from
ever being serialized in order to solve a problem in which the declarations
were being serialized inappropriately. That's too heavy handed, though, because
an `@_alwaysEmitIntoClient` function with `package` access *must* be serialized
because it has public non-abi linkage.

Resolves rdar://104711625
2023-12-18 15:06:19 -08:00
Robert Widmann
a987ba48d0 Don't Serialize Declarations with package Access
This accidentally started happening when I adjusted getEffectiveAccess to return `Public` for `Package` declarations in #69709. As a result, the optimizer thought it had more opportunities to go after declarations that used to be opaque. Unfortunately, this resulted in a miscompile as the devirtualizer was able to look through now-serialized package (static) functions. In one specific instance, the optimizer created direct calls to hidden accessors instead of going through the dispatch thunk.
2023-11-29 14:09:48 -07:00
Yuta Saito
79b3d2d626 Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal
users that it's not stable yet by adding an underscore prefix.
2023-11-07 02:01:02 +00:00
Varun Dhand
528894e8ca fix: typo in SILDeclRef.cpp from intializers to initializers 2023-10-30 23:12:01 +05:30