1627 Commits

Author SHA1 Message Date
Alexis Laferrière
e0014b4ed7 [Serialization|NFC] Move free floating functions to methods
Move some deserialization error handling services to methods under ModuleFile.
This will give access to the ASTContext and allow to report diagnostics.

Also rename `consumeErrorIfXRefNonLoadedModule` into the more general
`consumeExpectedError` that is more appropriate for future improvements.
2023-05-18 14:21:04 -07:00
Alexis Laferrière
74fd209c73 Merge pull request #65713 from xymus/report-modularization-breaks
[Serialization] Report modularization breaks as proper diagnostics
2023-05-18 13:57:35 -07:00
Alexis Laferrière
144d7eb8a0 [Serialization] Report detected modularization breaks
The Swift compiler expects the context to remain stable between when a
module is built and loaded by a client. Usually the build system would
rebuild a module if a dependency changes, or the compiler would rebuilt
the module from a swiftinterface on a context change. However, such
changes are not always detected and in that case the compiler may crash
on an inconsistency in the context. We often see this when a clang
module is poorly modularized, the headers are modified in the SDK, or
some clang define change its API.

These are project issues that used to make the compiler crash, it
provided a poor experience and doesn't encourage the developer to fix
them by themselves. Instead, let's keep track of modularization issues
encountered during deserialization and report them as proper errors when
they trigger a fatal failure preventing compilation.
2023-05-17 10:23:33 -07:00
Alexis Laferrière
008047f1fd [Serialization] Intro ModuleFile::getSourceLoc()
Generate a fake empty buffer to return a SourceLoc pointing to the
beginning of a swiftmodule file.
2023-05-17 10:21:54 -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
Slava Pestov
394e3055d1 Serialization: Fix PackConformance deserialization 2023-04-20 00:02:28 -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
Slava Pestov
651bfcb917 Serialization: Simplify PackType serialization 2023-04-17 16:22:20 -04: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
Alexis Laferrière
ddf85dbe65 Merge pull request #64991 from xymus/serial-opaque-types
[Serialization] Only read the underlying type of an opaque type if inlinable
2023-04-07 16:11:58 -07:00
Alexis Laferrière
445307beec [Serialization] Always read opaque type underlying types in merge-module
When reading a swiftmodule that's part of the main module the compiler
should have access to all internal details. In that case, read the
underlying type to opaque types.

This was caught by `SILOptimizer/specialize_opaque_result_types2.sil`
which has a merge-module like behavior reading it sib files as input.
2023-04-07 08:37:06 -07:00
Alexis Laferrière
8ba60da81f [Serialization] Only write the underlying type of an opaque type if inlinable
Clients of a resilient module using opaque types don't need access to
the underlying type unless it's used in an inlinable context. Plus, the
underlying type can reference internal details which can lead to crashes
when they reference implementation-only dependencies. To clean up this
behavior, let's only serialize the underlying type if used by an
inlinable function.

rdar://105128784
2023-04-07 07:49:45 -07: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
Slava Pestov
3d9a79e4b1 Merge pull request #64777 from slavapestov/sil-optimizer-variadic-generics
SIL optimizer fixes for variadic generics
2023-04-03 11:30:03 -04:00
Slava Pestov
1d27f5b386 Serialization: Actually deserialize same-shape requirements
I added a test for this a while ago... but the test wasn't running. Fix the
test, and fix the bug.
2023-03-30 14:10:27 -04:00
Doug Gregor
38230b79f9 [Macros] Add (de-)serialization for expanded macro definitions 2023-03-29 16:32:32 -07:00
Becca Royal-Gordon
43e48ef37f Better support destructors in objcImpl 2023-03-25 14:52:40 -07:00
Alexis Laferrière
1ec1df6f03 [Serialization] Pass up deserialization errors under generic type params
There is no related test as we don't have reproducer code and we've seen
it only in the debugger, but I believe the fix is sound on its own.

rdar://106430304
2023-03-24 13:49:53 -07:00
John McCall
09018a8981 [NFC] Store interface shape types in opened element environments 2023-03-15 17:25:04 -04:00
Kavon Farvardin
ea1e83b1d7 move noncopyable types out from behind the feature flag
Since these types depend on lexical borrow scopes (a SIL
option), we're now making that the requirement whenever
such types appear.
2023-03-13 22:39:31 -07:00
Doug Gregor
ef7f707fcc Revert "Improve @objcImplementation member checking" 2023-03-10 12:00:33 -08:00
Xi Ge
ffc998a0e7 Merge pull request #63668 from beccadax/checkmate
Improve @objcImplementation member checking
2023-03-06 08:21:59 -08:00
Becca Royal-Gordon
2c0abf0362 Better support destructors in objcImpl 2023-03-03 17:27:39 -08:00
Joe Groff
5345e982e9 Only mangle borrowing/consuming when they would change ABI.
`__shared` and `__owned` would always get mangled, even when they don't have any effect
on ABI, making it unnecessarily ABI-breaking to apply them to existing API to make
calling conventions explicit. Avoid this issue by only mangling them in cases where they
change the ABI from the default.
2023-03-02 21:33:29 -08:00
Michael Gottesman
c97121d3ee [reference-binding] Add support for inout binding parsing/serialization. 2023-03-01 20:48:54 -08:00
Michael Gottesman
ed57d882d3 [ast] Refactor BindingPattern to take a VarDecl::Introducer directly instead of a bool to mean a let.
I am going to be adding more VarDecl::Introducers so this is a small nice
cleanup that is cut off the larger patch.
2023-03-01 20:48:33 -08:00
Joe Groff
17c803724f Implement consuming and borrowing declaration-level modifiers from SE-0377.
`borrowing func`/`consuming func` control the ownership convention of `self` for
methods.
2023-03-01 11:58:59 -08:00
Joe Groff
655e9e681d Add ParamSpecifier cases for Borrowing and Consuming.
And do a first pass of auditing existing uses of the parameter specifiers to
make sure that we look at the ValueOwnership mapping in most cases instead of
individual modifiers.
2023-02-28 09:16:44 -08:00
Holly Borla
a3caacd309 [Macros] Initial implementation of conformance macros. 2023-02-23 20:43:11 -08:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Allan Shortlidge
8fde58f6ca Merge pull request #63357 from tshortli/se0376-rename-backdeploy
[SE-0376] Rename `@_backDeploy(before:)` to `@backDeployed(before:)`
2023-02-02 12:36:53 -08:00
Doug Gregor
d06e84d253 [Serialization] Make sure we serialize ALL macro roles 2023-02-01 22:34:32 -08:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
Alexis Laferrière
2d8f075333 [Serialization] Drop any failed overriding relationship when allowing errors 2023-01-30 14:31:19 -08:00
Alexis Laferrière
9c16b4b013 [Serialization] Drop overridden relationship in constructors when safe
Deserialization recovery lead the compiler to drop public constructors
overridding internal constructors. This limits the logic to dropping the
overriding relationship instead of the whole constructor. This applies
when the overriden constructor fails to deserialize and only when the
overriding relationship was marked as not affecting ABI.

rdar://104704832
2023-01-30 11:12:24 -08:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Doug Gregor
af7ce9e945 [Macros] Remove the @declaration attribute.
We have @freestanding working appropriately now.
2023-01-25 17:07:38 -08:00
Doug Gregor
d74f235eb9 Generalize @attached parsing and representation to also include @freestanding.
The attached and freestanding macro attributes use the same parsing
logic and representation, so generalize the "attached" attribute into
a more general "macro role" attribute.
2023-01-25 17:07:38 -08:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Holly Borla
5d7b280889 [Macros] Use @attached for member attribute macros.
Add MemberAttributes to MacroRole that corresponds to a `memberAttributes`
argument to the `@attached` attribute.
2023-01-15 10:11:00 -08:00
Doug Gregor
43cadcad3a [Macros] Serialization and printing for @attached. 2023-01-14 21:48:43 -08:00
Doug Gregor
de16b47875 [Macros] Introduce the @attached attribute for declaring attached macros.
Describe attached macros with the `@attached` attribute, providing the
macro role and affected names as arguments to the macro. The form of
this macro will remain the same as it gains other kinds of attached
macro roles beyond "accessor".

Remove the "accessors" role from `@declaration`, which will be going
away.
2023-01-13 22:47:59 -08:00
Alexis Laferrière
892ed0ece3 Merge pull request #62980 from xymus/recover-opaque-types
[Serialization] Recover in opaque type deserialization logic on XRef errors
2023-01-12 16:32:26 -08:00
Alexis Laferrière
4507307b35 Merge pull request #62982 from xymus/deser-safety-step2
[Serialization] Misc prep for the deserialization safety feature
2023-01-12 13:42:28 -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
Alexis Laferrière
165930b383 [Serialization] Accept DeclDeserializationUnsafe where we accepted XRef failures 2023-01-11 15:11:11 -08:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00