Commit Graph

1705 Commits

Author SHA1 Message Date
Alexis Laferrière
a91bb4965a [Serialization] Tweaks to deserialization safety writer logic
Apply reviewers comments and fix test.
2023-01-19 09:47:32 -08:00
Alexis Laferrière
77d8c464df [Serialization] Recover from deserialization failures in ModuleFile::lookupObjCMethods
This was reported by deserialization safety in:

Interpreter/SDK/Foundation_NSString.swift
2023-01-18 16:36:33 -08:00
Alexis Laferrière
88d796b4f2 [Serialization] Test looking through all possible members of AnyObject
Loading all possible members for the static type AnyObject can trigger
deserialization of members of non-public types. Deserialization safety
should prevent this by refusing to load the members themselves and even
avoid accessing their context.
2023-01-18 16:36:11 -08:00
Alexis Laferrière
2dff001be3 [Serialization] Update deserialization skipping test to reflect the safe behavior 2023-01-18 14:47:13 -08:00
Alexis Laferrière
4e8011179a [Serialization] Main deserialization safety logic on the writer side
When writing decls to a swiftmodule files, the serialization logic
evaluates whether the decl will be safe to deserialize. This is inferred
from the access level of the decl, whether it's local, if the module is
built for testing, etc. If the decl in unsafe to deserialize, a record
will be written down before the decl itself in the swiftmodule file.

On the reader side, attempting to deserialize a decl marked as unsafe
raises a deserialization error early. This error is handled by the existing
deserialization recovery logic.

In theory, we want to consider as safe only decls that are actually needed by
the client. Marking as many internal details as possible as unsafe will
prevent more errors. Getting the right scope may require more work in
the future.
2023-01-18 14:41:22 -08:00
Holly Borla
20f51b2981 Merge pull request #63075 from hborla/macro-attribute-serialization
[Serialization] Don't serialize macro custom attributes.
2023-01-17 21:23:24 -08:00
Holly Borla
ae1f8248b3 [Serialization] Don't serialize macro custom attributes. 2023-01-17 17:24:52 -08:00
Alexis Laferrière
ce91d77ab7 Merge pull request #63068 from xymus/serial-pub-override
[Serialization] Public overrides of internal decls are ignorable by clients
2023-01-17 15:37:59 -08:00
Alexis Laferrière
6c6cd41afd [Serialization] Public overrides of internal decls are ignorable by clients
This change reflects the behavior of `DeclAttribute.printImpl` that
prints the `override` keyword in a swiftinterface only when the
overriden decl is also public.

This issue was detected when working on deserialization safety by public
overrides of private functions in the following tests:

test/Interpreter/vtables_multifile.swift
test/Interpreter/vtables_multifile_testable.swift
test/SILGen/accessibility_vtables_testable.swift
test/SILGen/accessibility_vtables_usableFromInline.swift
test/SILGen/vtables_multifile.swift
2023-01-17 09:39:59 -08:00
Doug Gregor
d70e16b510 Merge pull request #63040 from DougGregor/attached-attr-deserialization-printing 2023-01-15 07:46:28 -08:00
Doug Gregor
43cadcad3a [Macros] Serialization and printing for @attached. 2023-01-14 21:48:43 -08:00
Mishal Shah
9757ccfc45 Bump the Swift version to 5.9 (#63014) 2023-01-13 16:03:25 -08:00
Alexis Laferrière
8741ad496a [Test] Add availability checks to implementation-only-opaque-type 2023-01-12 11:02:32 -08:00
Alexis Laferrière
71f116ca6f [Serialization] Recover in opaque type logic
If the underlying type of an opaque type references an
implementation-only imported type, drop the underlying type information.

Without this fix, once we enable deserialization safety, we see crashes
or dropped decls in more existing tests:

IRGen/mangle-opaque-return-type.swift
IRGen/opaque_result_type_private_underlying.swift
Serialization/Recovery/implementation-only-opaque-type.swift

rdar://103238451
2023-01-12 09:11:10 -08:00
Pavel Yaskevich
60c8bdad72 [Tests] TypeWrappers: Require asserts for type wrapper roundtrip tests 2023-01-09 00:29:08 -08:00
Holly Borla
6725f365ba [Variadic Generics] Update tests for syntax changes. 2023-01-07 09:50:14 -08:00
Alexis Laferrière
4e69160b92 Merge pull request #62886 from xymus/deser-safety-infra
[Serialization] Prepare the infrastructure for the deserialization safety feature
2023-01-06 21:08:24 -08:00
Allan Shortlidge
5d0a354b76 Merge pull request #62876 from tshortli/remove-back-deploy-available-attr-requirement
Sema: Lift restriction requiring decls with `@_backDeploy` to have explicit availability
2023-01-06 14:17:42 -08:00
Alexis Laferrière
c76dab7fb7 [Serialization] Debug print decls being read
These prints can be enabled in an assert compiler with `-Xllvm
-debug-only=Serialization`.
2023-01-06 12:02:47 -08:00
Pavel Yaskevich
ec5dc4cc8a Merge pull request #62856 from xedin/rdar-103445432
[MiscDiagnostics] OpaqueTypes: Handle unrelated #available conditions…
2023-01-06 11:21:04 -08:00
Allan Shortlidge
8e46b76882 NFC: Update @_backDeploy tests to remove @available attributes where possible. 2023-01-06 08:18:00 -08:00
Pavel Yaskevich
740ae8d4e7 [Tests] TypeWrappers/NFC: Add a tests to round-trip type wrappers in swift interfaces 2023-01-04 16:27:35 -08:00
Pavel Yaskevich
3c03449797 [MiscDiagnostics] OpaqueTypes: Handle unrelated #available conditions gracefully
`OpaqueUnderlyingTypeChecker` should skip conditional availability
blocks if none of the conditions restrict the current target.

Resolves: rdar://103445432
2023-01-04 15:36:46 -08:00
Alexis Laferrière
0db4ee4d82 Merge pull request #62653 from xymus/deser-custom-attr-cycle-alt
[Serialization] Deserialize custom attributes after the attached decl
2023-01-03 12:54:59 -08:00
Doug Gregor
1b14b5d356 Fixup some test cases 2023-01-02 21:22:05 -08:00
Doug Gregor
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Alexis Laferrière
59d1df7bb8 [Serialization] Wait after the decl to deserialize custom attrs
With type-wrappers a custom attribute may reference a type and lead to a
cycle in deserialization if the target type references the type-wrapper.
To avoid this scenario, move deserializing the custom decls from before
to after the decl they are attached to.

rdar://103425758
2022-12-21 14:11:42 -08:00
Erik Eckstein
beb46eb624 Use the new escape and side effects in alias analysis 2022-12-21 17:41:46 +01:00
Erik Eckstein
21b4004d69 Devirtualizer: don't de-virtualize witness calls to non-generic thunks which call a generic function.
If the callee is a non-generic thunk which calls a (not inlinable) generic function in the defining module,
it's more efficient to not devirtualize, but call the non-generic thunk - even though it's done through the witness table.
Example:
```
  protocol P {
    func f(x: [Int])   // not generic
  }
  struct S: P {
    func f(x: some RandomAccessCollection<Int>) { ... } // generic
  }
```

In the defining module, the generic conformance can be fully specialized (which is not possible in the client module, because it's not inlinable).

rdar://102623022
2022-12-21 08:52:53 +01:00
Ellie Shin
72ee150982 Add -package-name flag
De/serialize package name in module binary
Resoles rdar://103531218, rdar://103531208
2022-12-19 14:33:44 -08:00
Doug Gregor
3be6344619 Eliminate dependencies on _SwiftSyntaxMacros having actual macros in it 2022-12-14 16:13:48 -08:00
Allan Shortlidge
e0cce4a45d Serialization: Update -experimental-skip-non-inlinable-function-bodies SIL verification for @_backDeploy.
SIL verification was failing for modules containing functions with `@_backDeploy` because `SILSkippingChecker` expected the `SILFunction` corresponding to the resilient copy of back deployed function to be empty. Since the overall function declaration for a back deployed function is considered inlinable, the body will be typechecked and SILGen emits both the fallback copy of the function and the resilient copy of the function. The checker should therefore expect to see back deployed functions that are not marked as serialized.
2022-12-06 17:15:17 -08:00
Evan Wilde
5f9ac391be Requires-asserts macro tests
Macros are an experimental feature, as such are not available on
non-asserts compilers.

Adding requires asserts to remaining experimental macro tests.
 - ModuleInterface/macros.swift
 - Serialization/macros.swift
2022-12-01 11:18:10 -08:00
Alexis Laferrière
0ce8b48e0d [Serialization] Expect missing custom attribute in deserializeDeclCommon
Attr can be null here if it was a custom attribute from an
implementation-only dependency.

rdar://102525437
2022-11-30 16:48:13 -08:00
Doug Gregor
e1102cc098 Merge pull request #62204 from DougGregor/macro-declarations
Macro declarations
2022-11-29 10:04:09 -08:00
Doug Gregor
e6ed154407 Macro tests only run in CI for macOS at the moment 2022-11-28 18:33:11 -08:00
Doug Gregor
4ce0834c51 [Macros] Serialization support for macro declarations. 2022-11-28 18:33:09 -08:00
Adrian Prantl
28d7f8813c Turn (most) deserialization errors from a crash into a fatal diagnostic (NFC)
Currently, ModuleFileSharedCore::fatal() calls abort(), which may be reasonable
in a swift-frontend invocation, but has dire consequences when the Swift
frontend is embedded into another process, for example, LLDB where the abort()
kills the entire debugging session.

This patch introduces a few alternatives to the ModuleFile::fatal() familiy of
functions that instead push a fatal diagnostic to the ASTContext's
DiagnosticsEngine and return an llvm::Error so the error can be roperly
communicated and the ASTContext can be wound down without killing the parent
process.

The transition is not complete, this patch does not yet handle
fatalIfUnexpected(), for example.

This patch is NFC for the Swift compiler: When DebuggerSupport in off
ModuleFile::diagnoseFatal() will still call abort(), but if it is on, the error
will be passed up, together with a pretty stack trace.

rdar://64511878
2022-11-28 15:54:27 -08:00
Allan Shortlidge
a84f96e023 Merge pull request #62097 from slavapestov/fix-rdar102300174
Disable variadic generics tests on noasserts builds
2022-11-14 16:51:41 -08:00
Pavel Yaskevich
e762d20568 Merge pull request #61982 from xedin/type-wrappers-on-protocols
[Sema] TypeWrappers: Allow type wrappers on protocols and inference from them
2022-11-14 12:46:48 -08:00
Slava Pestov
a72ce0076c Disable variadic generics tests on noasserts builds
Fixes rdar://problem/102300174.
2022-11-14 12:14:23 -05:00
Slava Pestov
07aae0cb4f Add minimal SILGen and Serialization tests for variadic generics 2022-11-12 02:13:54 -05:00
Michael Gottesman
78ffc87c70 [move-only] Make sure we can properly deserialize deinits from structs/enums.
We previously had a cast<ClassDecl> here. I changed it to NominalTypeDecl and
added tests for this.

rdar://102173184
2022-11-09 19:40:04 -08:00
Michael Gottesman
4fcc60e794 [move-only] When emitting a module, do not emit the body of the deinit of a move only type.
rdar://102173152
2022-11-09 19:40:04 -08:00
Pavel Yaskevich
c003e69d6b [Sema] TypeWrappers: Allow type wrapper inference from protocol conformances
- Infer type wrappers only from direct (declared on type) protocols
- Inferences from protocol to protocol is not allowed
- If type specifies a type wrapper attribute explicitly it has to
  match the one associated with a declared protocol, otherwise the
  declaration is going to be rejected as having multiple wrappers.
2022-11-08 16:15:56 -08:00
Michael Gottesman
5406131e8c [move-only] Emit a nice error if a move only type is imported into a module that does not have experimental-move-only enabled.
This just prevents user confusion when they forget to do this since weird
behavior /could/ result.

rdar://102062737
2022-11-07 16:11:46 -08:00
Allan Shortlidge
290dd6bcaf Test: Make load-file-permissions.swift test more tolerant of interrupted runs. 2022-10-30 17:08:06 -07:00
Alexis Laferrière
34779d46a9 Merge pull request #61789 from xymus/serial-rebuilt-bit
[Serialization] Write in the binary swiftmodule file whether it was rebuilt from a swiftinterface
2022-10-29 09:31:23 -07:00
Alexis Laferrière
41ec454129 [Serialization] Update error message on deserialization failure
This adds information about whether the module was built from source or
from a swiftinterface, whether it's resilient or not, and tweaks the
format.
2022-10-27 18:51:28 -07:00
Nate Chandler
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00