Commit Graph

1798 Commits

Author SHA1 Message Date
Allan Shortlidge
229398c01d Merge pull request #69141 from tshortli/silgen-lazy-typecheck
SILGen: Introduce option to skip non-exportable declarations
2023-10-12 10:49:06 -07:00
Yuta Saito
051bf4dd43 Merge pull request #69107 from kateinoigakukun/yt/extern-wasm-sym
[wasm] Add @_extern(wasm) attribute support
2023-10-12 09:29:13 -07:00
Allan Shortlidge
a7daf13bf6 AST: Introduce and adopt Decl::isExposedToClients().
This method is a more ergonomic utility wrapping DeclExportabilityVisitor.
2023-10-11 22:41:31 -07:00
Slava Pestov
a3fa3bf110 Merge pull request #69038 from slavapestov/clean-up-associated-conformances
Preparation for lazily populating associated conformances
2023-10-11 20:58:27 -04:00
Slava Pestov
793c7a18e2 Serialization: Use forEachAssociatedConformance() 2023-10-11 15:04:09 -04:00
Allan Shortlidge
f131c8a3f5 Frontend: Introduce -experimental-skip-non-exportable-decls.
Rename -experimental-serialize-external-decls only to
-experimental-skip-non-exportable-decls in preparation for the flag being used
to influence more than just serialization.

Resolves rdar://116771543
2023-10-10 16:07:04 -07:00
Yuta Saito
bd898b0e7e [wasm] add @_extern(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
2023-10-10 22:42:08 +00:00
Holly Borla
3cb9bb89bc [Concurrency] Serialize default argument isolation. 2023-10-04 13:12:11 -07:00
Doug Gregor
51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Allan Shortlidge
497034ef64 AST: Requestify generic signature building for @_specialized attributes.
In order to support lazy typechecking during module emission for modules
containing specialized functions, the computation of generic signatures for
`@_specialized` attributes must be requestified.

Resolves rdar://115569606
2023-09-16 00:02:33 -07:00
Allan Shortlidge
82923d580d AST: Expose DeclExportabilityVisitor.
Extract `ExternallyAccessibleDeclVisitor` from `Serialization.cpp` into its own
header and rename it to `DeclExportabilityVisitor` to better align with
terminology in other parts of the compiler. Ideally, `DeclExportabilityVisitor`
should become the canoncial implementation of for exportability checks,
consolidating logic that is currently spread between serialization, module
interface printing, TBDGen, and type checking. For now, it is only used in
serialization to implement serialization safety checks.
2023-09-15 17:15:48 -07:00
Allan Shortlidge
1cec6a454f Serialization: Handle precedence groups and operators in ExternallyAccessibleDeclVisitor. 2023-09-14 18:11:03 -07:00
Allan Shortlidge
061578c1a8 Serialization: Handle IfConfigDecls in ExternallyAccessibleDeclVisitor. 2023-09-14 18:09:49 -07:00
Allan Shortlidge
4522963cf7 Serialization: Handle enum cases in ExternallyAccessibleDeclVisitor. 2023-09-14 17:59:17 -07:00
Allan Shortlidge
ee479fe21b Serialization: Use a DeclVisitor to implement deserialization safety.
Refactor deserialization safety to use a `DeclVisitor` CRTP instead of ad-hoc
casts. This ensures every kind of decl is handled explicitly.

Resolves rdar://115456536
2023-09-14 17:59:17 -07:00
Allan Shortlidge
9b641f9ba3 ModuleInterface: Typecheck PatternBindingDecls lazily before printing.
Previously, fully qualified types would be missing for global vars and
properties in `.swiftinterface` files that were emitted lazily.

Adding the test case also revealed that PatternBindingDecls needed to be
typechecked before lazy module serialization as well.
2023-09-12 09:08:10 -07:00
Allan Shortlidge
7c1b150f39 ModuleInterface: Resolve inherited types when computing unsatisfiable conformances.
Previously, unsatisfiable conformances could be omitted from emitted
`.swiftinterface` files in lazy typechecking mode since inherited types might
be unresolved when gathering the conformances.

Adding these test cases also revealed that serialization restrictions needed to
be relaxed in order to accomodate unsatisfiable conformances.
2023-09-07 13:57:39 -07:00
Kuba Mracek
25eb997a28 [embedded] Add basics of module serialization, importing and validation in embedded Swift.
- Add a flag to the serialized module (IsEmbeddedSwiftModule)
- Check on import that the mode matches (don't allow importing non-embedded module in embedded mode and vice versa)
- Drop TBD support, it's not expected to work in embedded Swift for now
- Drop auto-linking backdeploy libraries, it's not expected to backdeploy embedded Swift for now
- Drop prespecializations, not expected to work in embedded Swift for now
- Use CMO to serialize everything when emitting an embedded Swift module
- Change SILLinker to deserialize/import everything when importing an embedded Swift module
- Add an IR test for importing modules
- Add a deserialization validation test
2023-09-06 20:06:36 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Allan Shortlidge
bc85234e5b Serialization: Don't serialize conformances that should be skipped.
When `-experimental-serialize-external-decls-only` is specified, skip
serializing conformances to protocols that should be skipped to avoid
unnecessary typechecking. Also, ensure type and value witnesses are resolved
lazily during serialization by passing `true` for `useResolver`.

Resolves rdar://114799742
2023-09-01 08:57:33 -07:00
Allan Shortlidge
0dd315717b Merge pull request #68200 from tshortli/consolidate-conformance-serialization
NFC: Consolidate logic for serializing conformances
2023-08-30 10:11:56 -07:00
Allan Shortlidge
4622873ba7 Serialization: Refine safety checks for extensions/protocols.
In https://github.com/apple/swift/pull/65267 deserialization safety was made
more conservative, allowing deserialization of any protocol and
deserialization of any extension declaring an explicit conformance to any
protocol. We can refine this to only allow deserialization of safe protocols
and deserialization of extensions declaring conformances to safe protocols.
Importantly, though, we must look up all conformances declared by the
extension, not just the explicit ones.

Resolves rdar://114673761
2023-08-29 21:58:40 -07:00
Allan Shortlidge
dbf6257247 NFC: Consolidate logic for serializing conformances.
This is motivated by needing to typecheck conformances before serializing them
when lazy typechecking is enabled. It will also provide a centralized funnel
point for filtering out conformances we don't want to serialize.
2023-08-29 16:42:56 -07:00
Allan Shortlidge
5186971a02 Frontend: Introduce -experimental-serialize-external-decls-only option.
This option is designed to be used in conjunction with
`-experimental-lazy-typecheck` and `-experimental-skip-all-function-bodies`
when emitting a resilient module. The emitted binary module should contain only
the decls needed by clients and should contain roughly the same contents as it
would if the corresponding swiftinterface were emitted instead and then built.

This functionality is a work in progress. Some parts of the AST may still get
typechecked unnecessarily. Additionally, serialization does not trigger the
appropriate typechecking requests for some ASTs and then fails due to missing
types.

Resolves rdar://114230586
2023-08-28 21:22:20 -07:00
Allan Shortlidge
8ce8c364d8 Serialization: Make options a member of Serializer class.
Instead of passing options piecemeal to each method on Serializer, store the
options on construction. NFC.
2023-08-25 11:42:17 -07:00
Luciano Almeida
499547a3b8 [Serialization] Remove serialization code for initializes() and accesses() attributes 2023-08-22 20:57:30 -03:00
Slava Pestov
e5c7d251a2 Serialization: Fix serializing normal conformance xrefs for tuple conformances
Fixes rdar://problem/113707902.
2023-08-10 16:15:45 -04:00
Slava Pestov
f219274e9b AST: Remove generic signature and conditional requirements from BuiltinProtocolConformance 2023-08-09 17:42:57 -04:00
Joe Groff
16c59fa12c Merge pull request #67588 from jckarter/raw-layout-multi-file
Requestify raw layout "like" type resolution.
2023-07-31 08:38:49 -07:00
Joe Groff
56f2ae6b08 Requestify raw layout "like" type resolution.
This ensures it's resolved on demand even across files. rdar://112998213
2023-07-28 13:46:50 -07:00
Allan Shortlidge
874b318e3f NFC: Suppress implicit conversion warning in Serialization.cpp. 2023-07-27 12:45:28 -07:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
Saleem Abdulrasool
19f4b6f6e6 Merge pull request #67369 from compnerd/static-serialization
Serialization: allow `IS_STATIC_LIBRARY` to be deserialised properly
2023-07-19 07:14:48 -07:00
John McCall
a934f1f66c Merge pull request #67368 from rjmccall/unimplementable-variadic-reabstraction
Diagnose attempts to reabstract variadic functions in unimplementable ways
2023-07-18 21:28:59 -04:00
Saleem Abdulrasool
8466ef6d80 Serialization: allow IS_STATIC_LIBRARY to be deserialised properly
Properly encode the field metadata to permit the deserialization by
`llvm-bcanalyzer` for aiding debugging.
2023-07-18 10:28:12 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Pavel Yaskevich
8a666dea6f [Serialization] InitAccessors: Use correct code for @storageRestrictions serialization 2023-07-17 17:57:32 -07:00
Pavel Yaskevich
387bcf3187 [Serialization] InitAccessors: Serialization for @storageRestrictions attribute 2023-07-07 10:00:36 -07:00
Holly Borla
c867c7c917 [Macros] Allow extension macros to specify conformances in the attached
attribute.
2023-06-28 00:42:23 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Rintaro Ishizaki
6fa0c14dfb [Macros] Make 'PluginSearchOption' a external union
Create a 'Kind' enum so that deserialization can use the kind instead of
a string option name.
2023-06-16 11:59:19 -07:00
Rintaro Ishizaki
706985df82 [Macros] Update plugin search options serialization
Previously plugin search options were serialized for each option kind.
Instead serialize them in the order specified.
2023-06-15 17:32:59 -07:00
Alex Lorenz
ba8d4d7801 [cxx-interop] compilations that do not enable C++ interoperability should not be able to import modules that do enable C++ interoperability by default
A supplemental hidden frontend option allows advanced users to opt-out of this requirement.

Fixes https://github.com/apple/swift/issues/65833
Fixes https://github.com/apple/swift/issues/65832
2023-06-09 15:38:16 -07:00
Holly Borla
e5f75029de [AST] Add 'initializes' and 'accesses' attributes for init accessor
definite initialization dependencies.
2023-06-06 18:59:13 -07:00
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00
Alexis Laferrière
3dd13e7f08 Merge pull request #66309 from xymus/fix-serial-macros
[Serialization] Fix serializing CompilerPluginExecutablePaths values
2023-06-06 11:10:22 -07:00