Commit Graph

1726 Commits

Author SHA1 Message Date
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
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
Alexis Laferrière
4330921806 [Sema] Remove ImportFilterKind::SPIAccessControl
That filter wasn't needed in practice, we can remove it.
2023-03-03 11:42:59 -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
Ellie Shin
1a5882e373 Merge branch 'main' into es-declctx 2023-03-02 15:54:23 -08:00
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -08:00
Michael Gottesman
c97121d3ee [reference-binding] Add support for inout binding parsing/serialization. 2023-03-01 20:48:54 -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
85f2a1a234 [Macros] Factor calls to ResolveMacroRequest into Decl::getResolvedMacro.
This prevents call-sites from making the mistake of passing an incorrect
DeclContext to the request, which can cause re-typechecking issues.
2023-02-15 18:52:02 -08:00
Alexis Laferrière
9a1a32cd9b Merge pull request #63639 from xymus/serial-precise-tag
[Serialization] Don't fail the precise tag check if only the last digit doesn't match
2023-02-14 09:31:31 -08:00
Alexis Laferrière
4579e37e61 [Serialization] Intro distinct compiler revision string for serialization 2023-02-13 13:51:30 -08:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
Alexis Laferrière
4c51052a80 [Serialization] Evaluate the safety of opaque types
Some compilation paths access the opaque return type type by itself
without going through its function. So access to the type must be
protected, otherwise deserialization fails at getting the naming decl
when it's unsafe.

rdar://105085860
2023-02-07 09:36:18 -08:00
Alexis Laferrière
d2f5449251 Merge pull request #63365 from xymus/testable-safety
[Serialization] Disable deserialization safety when testing is enabled
2023-02-02 14:01: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
99747693a5 [Serialization] Disable deserialization safety when testing is enabled
Resilient modules with testing enabled expose internal non-resilient
internal types. These types cannot be reliably used by testable clients
if they don't have all of their members known. For this reason, this
disabled deserialization safety in modules when testing is enabled.

rdar://104923020
2023-02-01 19:37:25 -08:00
Alexis Laferrière
38030dd2a8 [Serialization] Limit ignoring internal overriden decl to lib evolution
At deserialization, we can drop the overriding relationship if the
overriden decl is internal and only when the overrider is in a resilient
module.
2023-01-30 11:12:24 -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
Alexis Laferrière
93704f6513 Merge pull request #63248 from xymus/swift-export-as
[ModuleInterface] Intro the flag `-export-as` for Swift modules
2023-01-27 21:23:35 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08: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
Holly Borla
8b9be30783 [Macros] Add a new macro role for synthesized member macros. 2023-01-22 21:19:21 -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
Alexis Laferrière
e032b3191d Merge pull request #63096 from xymus/deser-safety-writing
[Serialization] Introduce main deserialization safety logic, on the writer side
2023-01-19 13:22:25 -08:00
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
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
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
Holly Borla
3f462f0f43 [Decl] Add MissingDecl to use for parser recovery. 2023-01-15 09:55:15 -08:00