Commit Graph

1912 Commits

Author SHA1 Message Date
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
Michael Gottesman
508866a480 [noimplicitcopy] Be sure to register SILMoveOnlyWrappedTypeLayout with the AST serialization machinery.
This looks like a thinko from the early part of the implementation. Without
this, the machinery doesn't recognize the layout and just asserts.
2023-06-06 12:42:23 -04:00
Alexis Laferrière
7abb4c38e2 [Serialization] Fix serializing CompilerPluginExecutablePaths values
rdar://110068048
2023-06-02 14:18:03 -07:00
Ellie Shin
6eacb40ad3 Merge pull request #66261 from apple/es-spi
Add implicit SPI import feature
2023-06-02 12:27:40 -07:00
Slava Pestov
c1cd15fa3a Serialization: Fix serialization of PackElementType 2023-06-01 22:36:24 -04:00
Ellie Shin
32f53d1eb8 Add implicit SPI import feature
API development sometimes requires a redesign while supporting early
adopters. Currently this is done by adding @_spi(name) to the API but
that requires adding the attribute in import statements as well, causing
manual overhead of adding and then removing when the redesign is done.

This PR introduces a special spi group name '_' and allows an implicit
spi import of a module containing API attributed with '@_spi(_)'

Resolves rdar://109797632
2023-06-01 15:33:04 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Doug Gregor
d30feef92f Ensure that we serialize declarations in synthesized files
Without this, conformances synthesized by macros aren't visible
across modules.

Fixes rdar://109051626.
2023-05-08 22:21:21 -07:00
Alexis Laferrière
421042ec7c Merge pull request #65370 from xymus/serial-macro-paths
[Macros] Serialize plugin search paths for LLDB use
2023-05-02 09:20:16 -07:00
Rintaro Ishizaki
3ef6087d32 [Macros] Serialize plugin search paths for LLDB use
rdar://107030743
2023-05-01 14:04:39 -07:00
Doug Gregor
ae4a5ded8f [Macros] Improve parsing, representation, and serialization of role attributes
Parse compound and special names in the macro role attributes
(`@freestanding` and `@attached`). This allows both compound names and
initializers, e.g., `init(coding:)`.

Fixes rdar://107967344.
2023-04-21 11:36:06 -07:00
Alexis Laferrière
e8a5fa4f67 Merge pull request #65337 from xymus/spi-only-dep
[Serialization] Write down SPI only dependencies as required in swiftmodules
2023-04-20 22:00:37 -07:00
Alexis Laferrière
6be76a503f [Serialization] Mark SPI only dependencies as required in swiftmodules
rdar://108326858
2023-04-20 18:01:29 -07:00
Slava Pestov
4ad199fb48 Merge pull request #65311 from slavapestov/open-pack-element-serialization
Fix serialization of open_pack_element and tweak variadic generic function mangling
2023-04-20 09:01:46 -04:00
Slava Pestov
24b4dd6219 SIL: Fix serialization of open_pack_element 2023-04-19 23:15:36 -04:00
Slava Pestov
2f3a9465c3 Merge pull request #65300 from slavapestov/serialize-pack-conformance
Serialize pack conformances
2023-04-19 20:26:37 -04:00
Slava Pestov
493494f42f Serialization: Remove unused mapConformanceOutOfContext() / mapConformanceRefIntoContext() path 2023-04-19 16:41:51 -04:00
Slava Pestov
1e26137379 Serialization: Serialize PackConformance 2023-04-19 16:41:51 -04:00
Alexis Laferrière
cc0f42f509 Merge pull request #65267 from xymus/serial-indirect-conformances
[Serialization] Keep indirect conformances knowledge with safety
2023-04-19 10:52:20 -07:00
Alexis Laferrière
9602df1e83 [Serialization] Keep indirect conformances knowledge with safety
Given a scenario where a public type A, conforms to an internal protocol
B, which conforms to a public protocol C. A conforms indirectly to C
through a protocol that's hidden from the clients.

This is handled in module interface by printing the indirect conformance
of A to C explicitly at the end of the swiftinterface.

We have the same problem with deserialization safety that used to hide
the internal protocols from clients, thus breaking the knowledge of the
indirect dependency. To keep the indirect conformances, let's consider
all protocols as safe and preserve their conformance information.

rdar://105241772
2023-04-18 14:10:06 -07:00
Slava Pestov
5681a398c5 Serialization: Fix various problems with SIL serialization of variadic generic instructions
Fixes rdar://108004074.
2023-04-17 16:22:20 -04:00
Slava Pestov
651bfcb917 Serialization: Simplify PackType serialization 2023-04-17 16:22:20 -04:00
Alexis Laferrière
35da8fbe1b [Serialization] Make package access-level compatible with deserialization safety 2023-04-13 13:39:14 -07:00
Anthony Latsis
39c9ae2fc6 [NFC] ExistentialRequiresAnyRequest → HasSelfOrAssociatedTypeRequirementsRequest
The current name is misleading because it suggests that the request accounts
for language feature state, which it does not (and is not supposed to).
2023-04-13 07:50:06 +03:00
Richard Wei
01e6fe2936 [Macros] Code item macros
Add support for declaring and expanding code item macros.  Add experimental feature flag `CodeItemMacros`.
2023-04-04 09:54:57 -07:00
Richard Wei
eb8e984b97 [Macros] Private discriminators for outermost-private MacroExpansionDecl (#64813)
Add a private discriminator to the mangling of an outermost-private `MacroExpansionDecl` so that declaration macros in different files won't have colliding macro expansion buffer names.

rdar://107462515
2023-03-31 20:36:29 -07:00
Doug Gregor
38230b79f9 [Macros] Add (de-)serialization for expanded macro definitions 2023-03-29 16:32:32 -07:00
Doug Gregor
9292231e1f [Macros] Start recording expanded macro definitions and replacements
Handle a trivial macro defined in terms of another macro.
2023-03-29 16:32:28 -07:00
Alexis Laferrière
599346885e [Serialization] Differentiate module loading behavior for non-public imports
Differentiate `internal` and `fileprivate` imports from
implementation-only imports at the module-wide level to offer a
different module loading strategy. The main difference is for non-public
imports from a module with testing enabled to be loaded by transitive
clients.

Ideally, we would only load transitive non-public dependencies on
testable imports of the middle module. The current module loading logic
doesn't allow for this behavior easily as a module may be first loaded
for a normal import and extra dependencies would have to be loaded on
later imports. We may want to refactor the module loading logic to allow
this if needed.

rdar://106514965
2023-03-21 16:46:53 -07:00
Alexis Laferrière
205a2edf38 [Sema] Intro set of import filters for general use
Calling getImportedModules requires to list the desired kind of imports.
With the new kind of imports this has become cumbersome. Let's simplify
it by offering common sets of imports. Advanced call sites can still
list the desired imports explicitly.
2023-03-17 16:05:44 -07:00
Puyan Lotfi
d55cfd26da Merge pull request #61606 from NuriAmari/fwd-declarations
Import Forward Declared Objective-C Interfaces and Protocols
2023-03-08 21:44:47 -08:00
Nuri Amari
86c5698780 Implement importing of forward declared objc protocols and interfaces
This modifies the ClangImporter to introduce an opaque placeholder
representation for forward declared Objective-C interfaces and
protocols when imported into Swift.

In the compiler, the new functionality is hidden behind a frontend
flag -enable-import-objc-forward-declarations, and is on by default
for language mode >6.

The feature is disabled entirely in LLDB expression evaluation / Swift
REPL, regardless of language version.
2023-03-07 16:00:16 -08:00
Doug Gregor
3c779e7405 [Macros] Ensure that name lookup can find uniquely-generated macro names
While a Swift program cannot directly utter one of the unique names
produced by the macro expansion context outside of the macro itself,
utilities such as type reconstruction require the ability to look up
these names. Note that various kinds of macros can introduce unique
names, and update the name lookup facilities for macro-generated names
to account for them.

Fixes rdar://106053984.
2023-03-07 12:30:14 -08:00
Holly Borla
c1de4c8e33 [Serialization] Correct pack type serialization. 2023-03-07 01:10:45 -08:00
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
Alexis Laferrière
6980cf211b [Serialization] Intro package-only module wide information and serialize it 2023-03-03 11:43:20 -08:00