Commit Graph

2441 Commits

Author SHA1 Message Date
nate-chandler
3aca85bfb3 Merge pull request #74298 from nate-chandler/rdar129593468
[NoncopyableWrapperElim] Process undef values.
2024-06-12 06:55:48 -07:00
Nate Chandler
f39b70a86d [NFC] SIL: Extracted remove "any" m-o wrapping. 2024-06-11 16:25:29 -07:00
Nate Chandler
b5b637c72e [NFC] SIL: Renamed helper.
removing...To -> removing...From
2024-06-11 16:25:11 -07:00
Erik Eckstein
717880e844 PerformanceDiagnostics: avoid false meta-data alarms for non-loadable types
Non-loadable types don't necessarily need metadata, for example, structs with `@_rawLayout`

https://github.com/apple/swift/issues/73951
2024-06-10 18:25:08 +02:00
Doug Gregor
25830d6bc3 Merge pull request #74225 from DougGregor/flow-sensitive-actor-init-isolation
Teach `#isolation` to respect the flow-sensitive nature of actor initializers
2024-06-10 01:52:38 -07:00
Doug Gregor
d1ae73f436 Handle flow-sensitive #isolation in distributed actor initializers.
Distributed actors can be treated as actors by accessing the `asLocalActor`
property. When lowering `#isolation` in a distributed actor initializer,
use a separate builtin `flowSensitiveDistributedSelfIsolation` to
capture the conformance to `DistributedActor`, and have Definite
Initialization introduce the call to the `asLocalActor` getter when
needed.
2024-06-09 22:48:43 -07:00
Doug Gregor
956243cd7e Teach #isolation to respect the flow-sensitive nature of actor initializers
Actor initializers have a flow-sensitive property where they are isolated
to the actor being initialized only after the actor instance itself is
fully-initialized. However, this behavior was not being reflected in
the expansion of `#isolation`, which was always expanding to `self`,
even before `self` is fully formed.

This led to a source compatibility issue with code that used the async
for..in loop within an actor initializer *prior* to the point where the
actor was fully initialized, because the type checker is introducing
the `#isolation` (SE-0421) but Definite Initialization properly rejects
the use of `self` before it is initialized.

Address this issue by delaying the expansion of `#isolation` until
after the actor is fully initialized. In SILGen, we introduce a new
builtin for this case (and *just* this case) called
`flowSensitiveSelfIsolation`, which takes in `self` as its argument
and produces an `(any Actor)?`. Definite initialization does not treat
this as a use of `self`. Rather, it tracks these builtins and
replaces them either with `self` (if it is fully-initialized at this
point) or `nil` (if it is not fully-initialized at this point),
mirroring the flow-sensitive isolation semantics described in SE-0327.

Fixes rdar://127080037.
2024-06-07 14:54:20 -07:00
Meghana Gupta
af1d6017f9 Merge pull request #74132 from meg-gupta/deleteresultdependson
Remove resultDependsOn/resultDependsOnSelf
2024-06-06 10:23:31 -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
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
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Ellie Shin
c70c52175b Merge pull request #74070 from apple/elsh/pcmo-fixes
[SIL][PackageCMO] Fix dispatch thunk linker error and update table serialization
2024-06-04 18:30:25 -07:00
nate-chandler
365f811330 Merge pull request #74072 from nate-chandler/rdar64375208
[TypeLowering] Return pseudogeneric @autoreleasing
2024-06-04 16:53:48 -07:00
Ellie Shin
af9e5e6378 Merge branch 'main' into elsh/pcmo-fixes 2024-06-04 11:41:35 -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
Hamish Knight
6698ef4708 Merge pull request #74067 from hamishknight/macroscope
[Coverage] Avoid recording regions from macro expansions
2024-06-04 18:58:09 +01:00
Ellie Shin
5a0c73c45f Add isPackageCMOEnabled check for MethodInst and KeyPathInst.
Update lambda in table serialization.
Add more tests.
2024-06-03 23:39:04 -07:00
Hamish Knight
6c930f7aaa [Coverage] Also walk MacroExpansionDecls
Make sure we walk macro expansion decls to handle
cases where e.g a binding introduces control flow.
This should be a pretty uncommon case since bindings
introduced by macros aren't actually usable when
expanded in local contexts, but handle it all the
same.
2024-06-03 12:14:56 +01:00
Hamish Knight
95cbced7a0 [Coverage] Avoid profiling functions with body macros
These replace the body of the function, and as such
shouldn't be profiled.
2024-06-03 12:14:56 +01:00
Hamish Knight
98f0200f64 [Coverage] Avoid recording regions from macro expansions
Ignore any regions recorded while inside a macro
expansion, but account for any control flow that
may have happened such that the exit count is
correctly adjusted. This allows e.g throwing function
calls to behave correctly within the expansion.

rdar://129081384
2024-06-03 12:14:56 +01:00
Hamish Knight
f2a0b46d3e [Coverage] NFC: Set the SourceFile on CoverageMapping
Saves having to pass it as a parameter to
`emitSourceRegions`.
2024-06-03 12:14:56 +01: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
Michael Gottesman
c7124e431a [sending] Fix recent alloc_stack as indirect result isolation inference to infer disconnected if the alloc stack is used as a sending indirect result.
I also fixed an issue that I found where we were not substituting SILResultInfo
flags which was causing us to drop when substituting sil_sending. I added a
SILVerifier check to make sure that we do not break this again.
2024-06-01 23:25:16 -07:00
Nate Chandler
2d03664e45 [TypeLowering] Return pseudogeneric @autoreleasing
Previously, when a pseudogeneric function returned a type parameter, it
was unowned.  That resulted in invalid OSSA out of SILGen.  Here, this
is fixed to use the @autoreleasing convention.

rdar://64375208
2024-05-31 18:42:25 -07:00
Ellie Shin
fd07578b29 Package CMO fixes.
* Do not use [serialized_for_package] for witness method before Package CMO.
* Update v-table and witness-table and their entry serialization.
  -- Allow non-serialized but visible entries in a serialized table so they
    can be optimized by other SIL opt passes.
* Only serialize MethodInst if it has the right visibility.

Resolves rdar://129089105&129088935
2024-05-31 17:05:00 -07:00
Slava Pestov
ea1c3cd4ed SIL: Update lowerCaptureContextParameters() for PackElementExpr captures 2024-05-30 16:39:49 -04:00
Slava Pestov
fc25690723 SIL: Update getLoweredLocalCaptures() for PackElementExpr captures 2024-05-30 16:39:49 -04:00
Slava Pestov
52e908363f Sema: Collect PackElementExpr captures in CaptureInfoRequest 2024-05-30 16:39:49 -04: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
Hiroshi Yamauchi
d1ccba70d7 Handle generic self types as the isolation parameters.
This PR builds on https://github.com/apple/swift/pull/73129 and fixes
https://github.com/apple/swift/issues/73345.

Co-authored with @hyp.
2024-05-22 16:59:22 -07:00
Augusto Noronha
16755e938b Merge pull request #73727 from augusto2112/remove-dep-irgen
Remove dependency of SILFunction in IRGenOptions
2024-05-22 11:18:49 -07:00
eeckstein
7c69bec9b4 Merge pull request #73782 from eeckstein/static-arrays-in-embedded
IRGen: support read-only statically initialized arrays in embedded swift
2024-05-22 19:34:42 +02: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
Augusto Noronha
4aec4e7cc4 Remove dependency of SILFunction in IRGenOptions
SILFunction::shouldBePreservedForDebugger checks if some optimizations
are enabled to decide whether a function should be preserved so its
accessible form the debugger or not. Some of these settings used to live
only in IRGenOptions making SILFunction depend on IRGenOptions.
2024-05-21 15:30:15 -07:00
Slava Pestov
3d263bf8f7 Merge pull request #73775 from slavapestov/more-sil-cloner-cleanup
More SILCloner cleanups
2024-05-21 17:10:46 -04:00
Arnold Schwaighofer
2318b477e4 Merge pull request #73708 from aschwaighofer/ignore_aeic_in_package_context_without_ufi
SIL: Ignore AEIC on package declaration inside declarations without effective public access
2024-05-21 13:33:35 -07:00
Slava Pestov
a1462ef184 SIL: Promote removeDeadBlock() from SILOptimizer to a method on SILBasicBlock 2024-05-21 13:52:58 -04: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
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
e415c1a42f [SIL] [Package CMO] Remove resilience bailout that is an artifact of incremental development 2024-05-20 08:49:17 -07:00
Slava Pestov
c7c244e16a Merge pull request #73712 from slavapestov/pack-expansion-closures-part-6
Pack expansion closures, part 6
2024-05-18 07:41:44 -04:00
Michael Gottesman
d759ec97ea Merge pull request #73696 from gottesmm/rdar128216574
[sending] Add support for 'sending'
2024-05-18 05:42:41 -04:00
Slava Pestov
4fd4975961 SIL: Allow getGenericSignatureWithCapturedEnvironments() on all SILDeclRefs
The main entry point _does_ have a generic signature, it's just empty.
2024-05-17 15:16:11 -04:00
Slava Pestov
749c2af7e2 SIL: Add TypeConverter::getSubstitutionMapWithCapturedEnvironments() 2024-05-17 15:16:11 -04:00
Slava Pestov
e8714e7e5a SIL: Split off reclaimUnresolvedLocalArchetypeDefinitions()
Just to be extra safe, I'm only going to call this when captured local archetypes
are present.
2024-05-17 15:16:11 -04: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
Slava Pestov
9cf4d61ece Merge pull request #73685 from slavapestov/pack-expansion-closures-part-5
Pack expansion closures, part 5
2024-05-17 07:42:06 -04:00
Slava Pestov
a40a6e215d SIL: Fix assertion failure after deleting instructions that contain unresolved local archetypes
We maintained a counter of the number of pending local archetypes
that had not yet been defined. However, if an instruction that
references a pending local archetype was deleted before the
local archetype was defined, the counter would never decrement.

Before reading the counter value, garbage collect any inserted
placeholders that have no uses. These correspond to pending
local archetypes that are no longer in use and will never be
defined.
2024-05-16 23:00:44 -04:00