Commit Graph

1394 Commits

Author SHA1 Message Date
QuietMisdreavus
e45c9df2a3 always use the argNames constructor for macro DeclNames (#66497)
rdar://110179186
2023-06-12 09:10:02 -06:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Alexis Laferrière
b18e7f14a8 Merge pull request #66227 from xymus/recovery-notes
[Serialization] Display contextual notes on deserialization errors and misconfigurations
2023-06-09 12:09:06 -07:00
Alexis Laferrière
9804075549 [Serialization] Show contextual notes on deserialization errors
This PR makes diagnostics on deserialization errors caused by project
configuration more helpful by providing contextual information on the
issue:

- Path to the modules involved (up to 4 modules): the loaded swiftmodule
with the broken outgoing reference, the path to the module where the
decl was expected, the path to the underlying clang module, and the path
to the module where the decl was found. This information should prevent
us from having to ask for a different log with `-Rmodule-loading`.
- Hint to delete the swiftmodule files when the module is
library-evolution enabled.
- Hint that clang settings affect clang modules involved in this
scenario.
- Pointing out when a decl moved between two modules with a similar name
(where one name is a prefix of the other). This is a common issue when
headers are shared between a clang framework's public and private
modules.
- Pointing out layering issues when an SDK module imports a local
module.
- Pointing out Swift language version mismatch which may lead to the
compiler viewing the same clang decls differently when they are modified
by APINotes files.
2023-06-08 09:24:11 -07:00
Alexis Laferrière
b1e0b89cf7 [Serialization] Invert order of diagnostics in forced recovery mode 2023-06-07 16:03:08 -07:00
Alexis Laferrière
1cd4f4ac67 [Serialization] Intro ModularizationError::getSourceLoc
This service provides a path to the loaded swiftmodule file and
synthesizes pseudo-Swift code representing the reference.
2023-06-07 15:34:23 -07:00
Alexis Laferrière
2f03c952c3 [Serialization] ModularizationError keeps full objects
Preserve more information about the context of modularization errors by
replacing the module names with pointers to ModuleDecl and ModuleFile
objects.
2023-06-07 13:01:37 -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
Alexis Laferrière
814ca434f0 Merge pull request #66186 from xymus/force-workaround
[Serialization] Add flag to force unsafe recovery from some xref failures
2023-05-30 08:55:17 -07:00
Alexis Laferrière
261f32cb84 Merge pull request #66139 from xymus/r-module-recovery 2023-05-26 16:00:43 -07:00
Alexis Laferrière
d50f20e4a8 [Serialization] Make a warning the diagnostic about attempting recovery
Use the `attempting forced recovery` diagnostic as main warning to which
we attach other messages as notes. Also mention the flag in the
diagnostic to reinforce that the flag is active.
2023-05-26 15:28:01 -07:00
Alexis Laferrière
642980cbb1 [Serialization] Add flag to force unsafe recovery from some xref failures
Intro a deserialization mode controlled by the flag
`-experimental-force-workaround-broken-modules` to attempt unsafe
recovery from deserialization failures caused by project issues.

The one issue handled at this time is when a type moves from one module
to another. With this new mode the compiler may be able to pick a
matching type in a different module. This is risky to use, but may help
in a pinch for a client to fix and issue in a library over which they
have no control.
2023-05-26 14:36:28 -07:00
Alexis Laferrière
4f66fcfadb [Serialization] Intro -Rmodule-recovery to remark about silent errors
Deserialization recovery silently drops errors and the affected decls.
This can lead to surprises when a function from an imported module
simply disappears without an explanation.

This commit introduces the flag -Rmodule-recovery to report as remarks
some of these previously silently dropped issues. It can be used to
debug project configuration issues.
2023-05-25 10:44:08 -07:00
Alexis Laferrière
65b5f82b52 [Serialization|NFC] Extract some diagnostic logic into diagnoseModularizationError 2023-05-25 10:33:03 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Alexis Laferrière
a475f4c132 [Serialization|NFC] Intro diagnoseAndConsumeError
Intro the service `diagnoseAndConsumeError` as the ultimate site to drop
deserialization issues we can recover from. It will be used to raise
diagnostics on the issues before dropping them silently.
2023-05-18 14:25:26 -07:00
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