Commit Graph

3900 Commits

Author SHA1 Message Date
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
John McCall
bbda52f7e5 Merge pull request #63345 from rjmccall/pack-allocation
Add SIL instructions to stack-allocate packs
2023-02-01 21:50:23 -05:00
Artem Chikin
4eeaafa6fb Merge pull request #63310 from artemcm/ScanDepsNoImplOnlyDeps
[Dependency Scanning] Do not process transitive `@_implementationOnly` dependencies of binary Swift modules
2023-02-01 08:46:44 -08:00
John McCall
6bf9ac858b Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use
alloc_stack and dealloc_stack.  Well, if we find ourselves adding
a lot of redundancy with those instructions (e.g. around DI), we
can always go back and rip these out.
2023-01-31 22:39:34 -05:00
Alexis Laferrière
2d8f075333 [Serialization] Drop any failed overriding relationship when allowing errors 2023-01-30 14:31:19 -08:00
Artem Chikin
957f49add9 [Dependency Scanning] Do not process transitive '@_implementationOnly' dependencies of binary Swift modules
These modules are not guaranteed to be found, which is okay, as compilation is meant to be possible in their absense since their contents are not used in the public API of the module which imports them as implementation-only.

Resolves rdar://103031296
2023-01-30 14:25:23 -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
Egor Zhdan
ee6b9b2a67 [cxx-interop] Disallow import std, require import CxxStdlib
`CxxStdlib` will now be the only accepted module name for the C++ standard library module in Swift.
2023-01-26 14:15:56 +00:00
Richard Wei
dbbf6aa4f1 Merge branch 'main' into freestanding-macro-attr-cleanup 2023-01-26 18:09:45 +08:00
Pavel Yaskevich
c86c741eb7 Merge pull request #63198 from xedin/enable-runtime-attrs-on-enums
[AST] RuntimeMetadata: Allow using enums as custom runtime metadata types
2023-01-26 00:47:38 -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
Pavel Yaskevich
3eaa2d60d4 [Serialization] RuntimeMetadata: Bump format version due to attribute flags change 2023-01-25 10:14:30 -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
91f785441f Merge pull request #62652 from apple/es-pkg-acl
[NFC] Add 'package' access modifier to AccessLevel
2023-01-20 13:58:15 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05: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
77d8c464df [Serialization] Recover from deserialization failures in ModuleFile::lookupObjCMethods
This was reported by deserialization safety in:

Interpreter/SDK/Foundation_NSString.swift
2023-01-18 16:36:33 -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
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
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05: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
Holly Borla
2d893d23bf [GenericEnvironment] For opened pack element environments, only include element type
parameters whose originating packs are in a given shape equivalence class.
2023-01-08 12:59:08 -08:00
Alexis Laferrière
4e69160b92 Merge pull request #62886 from xymus/deser-safety-infra
[Serialization] Prepare the infrastructure for the deserialization safety feature
2023-01-06 21:08:24 -08:00
Alexis Laferrière
294b5d09a3 [Serialization] Raise an error (to recover from) when reading an unsafe decl
Intro UnsafeDeserializationError and instanciate it when attempting to
deserialize a decl marked as unsafe by a DESERIALIZATION_SAFETY record.
2023-01-06 12:02:48 -08:00
Alexis Laferrière
2c508d95b2 [Serialization] Intro the DESERIALIZATION_SAFETY record format
The DESERIALIZATION_SAFETY record will be used by the deserialization
safety feature to identify decls that are unsafe to read so they can be
skipped.
2023-01-06 12:02:47 -08:00
Alexis Laferrière
c76dab7fb7 [Serialization] Debug print decls being read
These prints can be enabled in an assert compiler with `-Xllvm
-debug-only=Serialization`.
2023-01-06 12:02:47 -08:00
Artem Chikin
b205a9c2c5 Merge pull request #62696 from artemcm/BetterScannerDependencyResolution
[Dependency Scanning] Refactor the scanner to resolve unqualified module imports
2023-01-05 17:48:21 -08:00
Artem Chikin
12477b7b79 [Dependency Scanning] Refactor the scanner to resolve unqualified module imports
This changes the scanner's behavior to "resolve" a discovered module's dependencies to a set of Module IDs: module name + module kind (swift textual, swift binary, clang, etc.).

The 'ModuleDependencyInfo' objects that are stored in the dependency scanner's cache now carry a set of kind-qualified ModuleIDs for their dependencies, in addition to unqualified imported module names of their dependencies.

Previously, the scanner's internal state would cache a module dependnecy as having its own set of dependencies which were stored as names of imported modules. This led to a design where any time we needed to process the dependency downstream from its discovery (e.g. cycle detection, graph construction), we had to query the ASTContext to resolve this dependency's imports, which shouldn't be necessary. Now, upon discovery, we "resolve" a discovered dependency by executing a lookup for each of its imported module names (this operation happens regardless of this patch) and store a fully-resolved set of dependencies in the dependency module info.

Moreover, looking up a given module dependency by name (via `ASTContext`'s `getModuleDependencies`) would result in iterating over the scanner's module "loaders" and querying each for the module name. The corresponding modules would then check the scanner's cache for a respective discovered module, and if no such module is found the "loader" would search the filesystem.

This meant that in practice, we searched the filesystem on many occasions where we actually had cached the required dependency, as follows:
Suppose we had previously discovered a Clang module "foo" and cached its dependency info.
-> ASTContext.getModuleDependencies("foo")
--> (1) Swift Module "Loader" checks caches for a Swift module "foo" and doesn't find one, so it searches the filesystem for "foo" and fails to find one.
--> (2) Clang Module "Loader" checks caches for a Clang module "foo", finds one and returns it to the client.

This means that we were always searching the filesystem in (1) even if we knew that to be futile.
With this change, queries to `ASTContext`'s `getModuleDependencies` will always check all the caches first, and only delegate to the scanner "loaders" if no cached dependency is found. The loaders are then no longer in the business of checking the cached contents.

To handle cases in the scanner where we must only lookup either a Swift-only module or a Clang-only module, this patch splits 'getModuleDependencies' into an alrady-existing 'getSwiftModuleDependencies' and a newly-added 'getClangModuleDependencies'.
2023-01-05 11:44:06 -08:00
Alexis Laferrière
0db4ee4d82 Merge pull request #62653 from xymus/deser-custom-attr-cycle-alt
[Serialization] Deserialize custom attributes after the attached decl
2023-01-03 12:54:59 -08:00
Doug Gregor
7000969f14 Introduce and use #externalMacro for externally-defined macros.
Align the grammar of macro declarations with SE-0382, so that macro
definitions are parsed as an expression. External macro definitions
are referenced via a referenced to the macro `#externalMacro`. Define
that macro in the standard library, and recognize uses of it as the
definition of other macros to use externally-defined macros. For
example, this means that the "stringify" macro used in a lot of
examples is now defined as something like this:

    @expression macro stringify<T>(_ value: T) -> (T, String) =
        #externalMacro(module: "MyMacros", type: "StringifyMacro")

We still parse the old "A.B" syntax for two reasons. First, it's
helpful to anyone who has existing code using the prior syntax, so they
get a warning + Fix-It to rewrite to the new syntax. Second, we use it
to define builtin macros like `externalMacro` itself, which looks like this:

    @expression
    public macro externalMacro<T>(module: String, type: String) -> T =
        Builtin.ExternalMacro

This uses the same virtual `Builtin` module as other library builtins,
and we can expand it to handle other builtin macro implementations
(such as #line) over time.
2023-01-02 21:22:05 -08:00