Commit Graph

1682 Commits

Author SHA1 Message Date
Artem Chikin
39e1791b67 Revert "Add support for inout lifetime dependence" 2025-04-04 09:00:09 -07:00
Meghana Gupta
364338283b [NFC] Update tests 2025-04-03 17:32:02 -07:00
Alejandro Alonso
b5e8f495f7 Fix serialization for InlineArray sugar 2025-03-26 12:37:34 -07:00
Allan Shortlidge
3af72e4dca Serialization: Skip invalid @available attributes during lazy serialization.
When performing lazy module serialization, we may be making the first attempt
to turn an `AvailableAttr` into a `SemanticAvailableAttr`. If it turns out the
attribute is invalid at that point, we need to skip it instead of assuming
that the attribute will always be valid there.

Resolves rdar://147539902.
2025-03-21 15:45:53 -07:00
Alexis Laferrière
2086df0e17 Merge pull request #80108 from xymus/deser-protect-enum-raw-type
Serialization: Protect `deserializeEnum` and more against failures
2025-03-20 09:04:24 -07:00
Alexis Laferrière
fe9c48cc8c Serialization: Protect getType for params and classes 2025-03-19 16:25:48 -07:00
Alexis Laferrière
06d2d4cb50 Serialization: Recover from missing raw types on an enum
Recover from a raw type hidden behind an internal or implementation-only
import by dropping the whole enum when the raw type is unavailable. This
scenario should happen only when looking at non-public decl for indexing or
debugging, or if dependencies somehow changed and left behind a stale
swiftmodule file.

rdar://147091863
2025-03-19 14:10:57 -07:00
Alexis Laferrière
6358cb9024 Serialization: Update style of the test implementation-only-missing 2025-03-19 14:10:56 -07:00
Andrew Trick
64a48d08e1 Update tests for strict @lifetime type checking 2025-03-19 11:59:04 -07:00
Alexis Laferrière
7ae7371b62 Merge pull request #80009 from xymus/deser-internal-shadow
Serialization: Ignore lookup shadowing when resolving cross-references
2025-03-18 10:42:38 -07:00
Alexis Laferrière
bf224e21f3 Serialization: Add test for more shadowing scenarios in inlinable code 2025-03-14 13:35:14 -07:00
Alexis Laferrière
18eb4e43e4 Serialization: Skip lookup shadowing when resolving cross-references
When a Swift function shadows a clang function of the same name, the
assumption was that Swift code would refer only to the Swift one.
However, if the Swift function is `@usableFromInline internal` it can be
called only from the local module and inlined automatically in other
clients. Outside of that module, sources see only the clang function, so
their inlinable code calls only the clang function and ignores the Swift
one. This configuration passed type checking but it could crash the
compiler at inlining the call as the compiler couldn't see the clang
function.

Let's update the deserialization logic to support inlined calls to the
shadowed or the shadower. Typical shadowing is already handled by the
custom deserialization cross-reference filtering logic which looks for
the defining module, scope and whether it's a Swift or clang decl. We
can disable the lookup shadowing logic and rely only on the
deserialization filtering.

rdar://146320871
https://github.com/swiftlang/swift/issues/79801
2025-03-14 12:35:18 -07:00
Doug Gregor
3837661b84 [Isolated conformances] Allow conformance isolation to differ from the type's
With the move to explicitly specifying the global actor for an isolated
conformance, we can now have conformances whose isolation differs from
that of the type, including having actors with global-actor-isolated
conformances. Introduce this generalization to match the proposal, and
update/add tests accordingly.
2025-03-12 23:18:28 -07:00
Doug Gregor
0e873e723c [Isolated conformances] Change syntax to @<global actor type> P
Instead of using the `isolated P` syntax, switch to specifying the
global actor type directly, e.g.,

   class MyClass: @MainActor MyProto { ... }

No functionality change at this point
2025-03-12 23:18:10 -07:00
Alexis Laferrière
c0a4056768 Merge pull request #79851 from xymus/deser-recover-conformance-xref
Serialization: Diagnose broken conformances from stale swiftmodule files
2025-03-11 15:07:38 -07:00
Alejandro Alonso
d0513a7aec Merge pull request #79665 from Azoy/value-generics-no-more-experiment
[AST] Make ValueGenerics feature always available
2025-03-10 15:14:34 -07:00
Alexis Laferrière
fb3944f1b1 Serialization: Error on mismatch between requirements and confirmances
When deserialization a protocol conformance from a binary swiftmodule
file the compiler can encounter inconsistencies caused by stale module
files. Replace the hard crash with a proper error and print the list of
requirements and conformances being compared to stderr for manual
inspection. Recover silently when we can afford to, during indexing or
in LLDB.
2025-03-07 14:05:57 -08:00
Alexis Laferrière
ea5658eece Serialization: Protect readNormalProtocolConformanceXRef
Failures in `readNormalProtocolConformanceXRef` are usually caused by a
dependency change without the required rebuild of its dependents.
Display a proper error instead of crashing when encountering such an
issue during normal compilation. Recover silently when we can afford to,
during indexing or in LLDB.
2025-03-07 14:05:57 -08:00
Alexis Laferrière
e97db1c844 Merge pull request #79487 from xymus/limit-nserror-optimization-to-import
SILGen: Ensure Foundation is publicly imported before referencing `NSError` in code gen
2025-02-28 15:21:11 -08:00
Alejandro Alonso
c1bb143648 Make ValueGenerics feature always available 2025-02-27 10:03:37 -08:00
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
Pavel Yaskevich
dd1be8f6d4 [Frontend] Hide @execution attribute behind an experimental feature ExecutionAttribute
Since the proposal has not been approved yet we cannot expose
`@execution` attribute.
2025-02-20 00:05:03 -08:00
Pavel Yaskevich
e2ff3308be [Frontend] NFC: Rename NonIsolatedAsyncInheritsIsolationFromContext feature
New name is `AsyncCallerExecution` as stated by the proposal.
2025-02-19 20:00:56 -08:00
Michael Gottesman
3ef18eaf1d Merge pull request #79300 from gottesmm/pr-12bede947a34719b34b1aa8ea6c126a6126d6dd6
[concurrency] Implement serialization for execution(caller)/execution(concurrent).
2025-02-19 18:29:02 -08:00
Alexis Laferrière
db7126c390 SILGen: Limit references to NSError in inlinable code optimization
Revisit the optimization that provides a fast path for instances of
`NSError` when erasing the `Error` type in `emitExistentialErasure`. It
generated references to `NSError` when the `Foundation` module was
loaded, no matter how it was imported. This lead to deserialization
failures at reading the swiftmodule when that reference was added to
inlinable code while `Foundation` was not a public dependency.

Fix this crash by limiting the optimization to all non-inlinable code
and only inlinable code from a module with a public dependency on
`Foundation`. This is the similar check we apply to user written
inlinable code, however here we use the module-wide dependency instead
of per file imports.

rdar://142438679
2025-02-19 15:34:20 -08:00
Alexis Laferrière
f8722df3b9 Merge pull request #79339 from xymus/error-sil-function-cache
Tests: Use a local cache for error-sil-function.swift
2025-02-14 13:23:40 -08:00
Michael Gottesman
1fc836c564 [concurrency] Persist caller isolation inheriting through serialization.
rdar://142790023
2025-02-12 12:36:13 -08: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
Alexis Laferrière
d6fb616047 Tests: Use a local cache for error-sil-function.swift
This test appears flaky and it looks to be related to errors on modules
in the SDK from the timing with other failures. The flackiness is likely
from non-determinism in the module cache. Update the test to use a local
cache, which is a good practice for any test importing a module from the
SDK.

rdar://144272339
2025-02-11 15:52:00 -08:00
Alex Hoppen
fc2ee364ef Merge pull request #78899 from ahoppen/rdar141440011
[Serialization] Ensure we run `InheritedTypeRequest` before serializing inherited type
2025-02-04 18:36:48 -08:00
Alexis Laferrière
6852e0b9bb Merge pull request #79092 from xymus/more-serial-remarks
Serialization: Report deserialization remarks from lookup services
2025-02-04 09:03:23 -08:00
Alexis Laferrière
66402f110a Serialization: use diagnoseAndConsumeError in ModuleFile.cpp 2025-02-03 11:09:04 -08:00
Alexis Laferrière
76533b8533 Serialization: update decl naming in test 2025-01-31 16:25:52 -08:00
Meghana Gupta
6f9167c29e Serialize after high level passes for -emit-sib 2025-01-30 17:10:04 -08:00
Erik Eckstein
830565b0f0 - test changes 2025-01-30 17:10:03 -08:00
Alex Hoppen
2cfccccdd1 [Serialization] Ensure we run InheritedTypeRequest before serializing inherited type
When using `-experimental-skip-all-function-bodies` we don’t run the `TypeCheckSourceFileRequest` and thus don’t go through the decl checker, which calls `InheritedTypeRequest` on all inheritance clauses. This means that the inherited entries are not populated by the time we serialize the module. Trigger the computation of inherited entries by calling `InheritedTypeRequest` during serialization.

Unfortunately, we can’t use the type returned by `getResolvedType` for the serialization because `getResolvedType` returns an inverted protocol type for suppressed conformances but during serialization, we want to serialize the suppressed type with a `isSuppressedBit`. We thus need to call `getEntry(i).getType()` again to get the type to serialize.

rdar://141440011
2025-01-27 08:32:18 -08:00
Allan Shortlidge
7ea778f3a0 Sema: Diagnose @backDeployed functions with missing bodies in swiftinterfaces.
A `@backDeployed` function printed in a `.swiftinterface` must have a function
body so that SILGen can emit a fallback copy to call when the back deployed
function is unavailable. Previously, the compiler would crash in SILGen when
compiling an interface containing a back deployed function without a body.

Resolves rdar://141593108.
2025-01-03 09:15:12 -08:00
Erik Eckstein
53d78abd01 Optimizer: enable SILCodeMotion in OSSA, but only for trivial values.
to-do: we should eventually remove code motion of retain and release instructions and implement them as semantic ARC optimizations in OSSA.
2025-01-02 11:01:39 +01:00
Doug Gregor
aab36f63f2 Revert "Sema: Diagnose @backDeployed functions with missing bodies in swiftinterfaces" 2024-12-21 21:53:46 -08:00
Allan Shortlidge
ebda3e2d44 Sema: Diagnose @backDeployed functions with missing bodies in swiftinterfaces.
A `@backDeployed` function printed in a `.swiftinterface` must have a function
body so that SILGen can emit a fallback copy to call when the back deployed
function is unavailable. Previously, the compiler would crash in SILGen when
compiling an interface containing a back deployed function without a body.

Resolves rdar://141593108.
2024-12-20 12:02:04 -08:00
Usama Hameed
203f906364 Serialize/Deserialize source locations for instructions (#77281)
This commit adds support for serializing and deserializing source locations for instructions.
2024-12-12 16:15:44 +05:00
Artem Chikin
9e60c4f297 Merge pull request #77991 from artemcm/SubFrameworksImplicit
Add additional implicit framework search path for Darwin platforms
2024-12-09 13:25:09 -08:00
Artem Chikin
faf0b21339 Add additional implicit framework search path for Darwin platforms
'/System/Library/SubFrameworks' will be searched for frameworks by the compiler implicitly when an SDK path is specified.

Resolves rdar://137454957
2024-12-05 13:56:52 -08:00
Richard Howell
a007833cc0 Add IsSDKRelative field to ModuleInterfaceLayout
When serializing the module interface path of an interface that
is part of the SDK, we serialize relative to the SDK path. During
deserialization we need to know if a path was serialized relative
to the SDK or not. The existing logic assumes any relative path
has been serialized relative to the SDK, which makes it impossible
to compile modules from relative swiftinterface paths that are not
part of the SDK.

Update the swiftmodule file to include an attribute to show if the
path was serialized relative to the SDK or not, which is used
during deserialization to correctly reconstruct the interface path.
2024-12-04 08:14:59 -08:00
Allan Shortlidge
7789ce85e1 Serialization: Stop serializing cached rename decls.
Rename decls are typically derived from the rename strings attached to a
`@available` attributes. It shouldn't be necessary to serialize the cached
rename decls since they can be rederived. The only decls that have rename decls
and don't have reanme strings are synthesized by ClangImporter and don't get
serialized.
2024-11-29 10:35:02 -05:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Erik Eckstein
f363c3296e SIL: change the textual SIL output of a re-borrow phi from @reborrow @guaranteed to @reborrow
It's redundant because only guaranteed phis can be reborrows.
2024-11-13 10:39:14 +01:00
Allan Shortlidge
b97e27279e Sema: Fix opaque type accessors with inactive availability conditions.
Opaque type metadata accessor functions could be miscompiled for functions that
contain `if #available` checks for inactive platforms. For example, this
function will always return `A` when compiled for macOS, but the opaque type
accessor would instead return the type metadata for `B`:

```
func f() -> some P {
  if #available(iOS 99, *) {
    return A() // Returns an A on macOS
  } else {
    return B()
  }
}
```

Resolves rdar://139487970.
2024-11-10 09:23:39 -08:00
Meghana Gupta
84a0d9c0b2 Remove -disable-experimental-parser-round-trip from @lifetime tests 2024-11-07 14:38:01 -08:00