Commit Graph

124 Commits

Author SHA1 Message Date
Allan Shortlidge
9e93b7b730 Frontend: Remove support for -experimental-spi-imports flag.
Its functionality has been superseded by `@_spiOnly import`. There are no
longer any known clients and the flag was already unsupported in Swift 6, so
the functionality is now removed (but the flag is only deprecated for Swift 5).

Resolves rdar://136867210.
2024-10-01 17:27:22 -07:00
Allan Shortlidge
71ee93ddac Frontend: Refactor import collection for module interface printing.
Consolidates duplicated code. NFC.
2024-09-30 18:40:04 -07:00
Doug Gregor
0aff85ced7 Emit mangled names for public symbols into the .swiftinterface
When the frontend option `-abi-comments-in-module-interface` is provided
during interface printing, the printed interface will contain
additional comments that provide the mangled names for public symbols.
This is an experiment in seeing how much information we can
meaningfully extract from a printed Swift interface for the purpose of
bridging with other languages.
2024-09-25 15:49:34 -07:00
Allan Shortlidge
a0a4ac3d55 ModuleInterface: Don't alias Foundation module in swiftinterfaces.
Skip aliasing Foundation when `-alias-module-names-in-module-interface` is
specified since it appears to confuse the typechecker. The module name
"Foundation" is hardcoded and checked in several places, so aliasing Foundation
may be changing some subtle behaviors.

Resolves rdar://128897610.
2024-09-04 20:28:55 -07:00
Allan Shortlidge
d4339198dc Merge pull request #75694 from tshortli/member-import-visibility-import-access-level
Sema: Add an access level to the fix-its for missing imports when appropriate
2024-08-05 14:40:36 -07:00
Alexis Laferrière
eea22c2f09 Merge pull request #75659 from xymus/shadow-dont-warn-with-alias-workaround
ModuleInterface: Don't warn on name conflict when the alias workaround is enabled
2024-08-05 12:38:00 -07:00
Allan Shortlidge
fff4bebc44 AST: Clarify SourceFile's existing missing imports record.
In anticipation of adding a new kind of missing import record to `SourceFile`,
clarify the purpose of the existing "missing imports" record with more specific
naming and documentation.
2024-08-05 11:28:26 -07:00
Alexis Laferrière
b4fb5720b2 ModuleInterface: Don't warn on name conflict when the alias workaround is enabled
This warning is designed to be an early report of name conflicts in
swiftinterfaces caused by a type having the same name as a module.
Make sure we silence this warning when the workaround
-alias-module-names-in-module-interface is enabled. This is what we
already do for -module-interface-preserve-types-as-written.

rdar://132990400
2024-08-02 14:48:29 -07:00
Allan Shortlidge
a621059f80 ModuleInterface: Avoid crashing on invalid extensions in lazy typechecking mode.
With `-experimental-lazy-typecheck` specified during module interface emission,
`collectProtocols()` may be the first piece of code to request the extended
type for a given extension and it therefore needs to ignore invalid extensions
and ensure that diagnostics are emitted.

Also, add some `PrettyStackTrace` coverage to `ModuleInterfaceSupport.cpp` to make
investigating future issues easier.

Resolves rdar://126232836.
2024-07-23 10:32:50 -07:00
Allan Shortlidge
a6faa5a4bf Frontend: Only print the -project-name flag in private and package interfaces.
Resolves rdar://130992944.
2024-07-03 09:10:48 -07:00
Allan Shortlidge
f6e30ea83c Frontend: Refactor how flags are saved for module interfaces.
There are two axes on which a saved frontend flag can be categorized for
printing in a `.swiftinterface` file:

1. Whether the flag is "ignorable" or not.
2. Which levels of interface the flag should be in (public, package).

This refactor ensures that those two axes are modeled independently and
prepares the infrastructure to allow flags to appear in the private and package
interfaces without being included in the public interface.
2024-07-03 09:10:48 -07:00
Allan Shortlidge
a28b729594 Frontend: Remove unused ModuleInterfaceOptionIgnorablePrivate. 2024-07-03 08:51:02 -07:00
Ellie Shin
87452c6cbf Remove string compute logic 2024-06-28 20:30:38 -07:00
Ellie Shin
ea8a05399f Drop package-name if needed in SaveModuleInterfaceArgs 2024-06-28 20:24:28 -07:00
Ellie Shin
e5b4655108 Option to disable printing package-name in public or private interface.
Having package-name flag in non-package interfaces causes them to be built as if
belonging to a package, which causes an issue for a loading client outside of the
package as follows.

For example, when building X that depends on A with the following dependency chain:
  X --> A --> B --(package-only)--> C

1. X itself is not in the same package as A, B, and C.
2. When dependency scanning X, and opening up B, because the scan target is in a
   different package domain, the scanner decides that B's package-only dependency
   on C is to be ignored.
3. When then finally building A itself, it will load its dependencies, but because
   the .private.swiftinterface of A still specifies -package-name, when it loads
   B, it will then examine its dependencies and deem that this package-only dependency
   on C is required.

Because (2) and (3) disagree, we get an error now when building the private A textual interface.

rdar://130701866
2024-06-28 15:06:21 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Kavon Farvardin
9eba052ab2 Merge pull request #74322 from kavon/se427-noimplicit-for-invertible
SE-427: Make conditional conformances to Copyable more explicit.
2024-06-12 22:03:49 -07:00
Kavon Farvardin
a1e14ae0c7 Sema: ext's must add solo invertible conformances
This helps prevent confusion after not inferring requirements if the
extension adds a Copyable conformance.
2024-06-12 14:44:22 -07:00
Alexis Laferrière
f53be71874 ModuleInterface: Print imports shadowed by a cross-import overlay
In some cases this import may be superfluous as it's also
`@_exported` imported by the overlay. However, when the overlay
is hidden and the import not printed, the import can go entierly
missing.
2024-06-12 10:06:05 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ellie Shin
2d9042386c Fixes package import stmt missing from .package.swiftinterface.
Resolves rdar://124309585
2024-03-13 14:35:57 -07:00
Slava Pestov
41df661160 AST: Use a builtin conformance for unconditional Copyable/Escapable
This generalizes what we were already doing for classes.
2024-03-07 15:07:47 -05:00
Ben Barham
1306f2b32a Merge pull request #71863 from bnbarham/remove-makearrayref
Use the new template deduction guides rather than `makeArrayRef`
2024-02-25 21:06:51 -08:00
Slava Pestov
8702101567 Frontend: Use getAllInheritedProtocols() 2024-02-24 07:25:59 -05:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
05615fa0e4 NFC: Rename TypeWalker's SkipChildren to SkipNode
For consistency with ASTWalker.
2024-02-05 15:27:25 +00:00
Pavel Yaskevich
7f6a8f865c [AST] NFC: Convert InheritedEntry flags to bitfields 2024-01-19 10:22:39 -08:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Kavon Farvardin
bd1330715c [NCGenerics] only print ~Copyable in interface
We can't simply emit the desugared, expanded version of the requirements
because there's no way to pretty-print the type `some ~Copyable` when
the `~Copyable`'s get replaced with the absence of `Copyable`. We'd be
left with just `some _` or need to invent a new top type so we can write
`some Top`. Thus, it's best to simply reverse the expansion of default
requirements when emitting a swiftinterface file.
2023-12-12 16:40:26 -08:00
Ellie Shin
9d716394b1 Add an interface mode getter/setter in PrintOptions and ModuleInterfaceOptions
Update args parsing
2023-11-13 13:48:07 -08:00
Ellie Shin
e5ca8e5c0b Allow loading package interface if in same package.
Add a new flag to enable package interface loading.
Use the last value of package-name in case of dupes.
Rename PrintInterfaceContentMode as InterfaceMode.
Update diagnostics.
Test package interface loading with various scenarios.
Test duplicate package-name.
2023-11-09 18:44:06 -08:00
Ellie Shin
aba3b6c24e Introduce a package interface.
It has an extension .package.swiftinterface and contains package decls
as well as SPIs and public/inlinable decls. When a module is loaded
from interface, it now looks up the package-name in the interface
and checks if the importer is in the same package. If so, it uses
that package interface found to load the module. If not, uses the existing
logic to load modules.

Resolves rdar://104617854
2023-11-08 14:56:20 -08:00
Rintaro Ishizaki
03bf349778 [Macros] Improve visitation of auxiliary decls
Use the same pattern as 'getAllMembers()'. This supports nested macro
expansion:
```
std::function<void(Decl *)> visit;
visit = [&](Decl *d) {
  doIt(d);
  d->visitAuxiliaryDecls(visit);
};
for (auto *d : decls)
  visit(d);
```

Don't visit auxiliary decls in `PrintAST::visit(Decl *)` this function
is only intended for single decl printing. The caller should visit them
separately. For that, add
`ModuleDecl::getTopLevelDeclsWithAuxiliaryDecls()`
2023-10-23 14:51:12 -07:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Alexis Laferrière
64cd96e629 Merge pull request #69210 from xymus/export-as-module-interface-by-default
ModuleInterface: Always ignore export-as for printing references in private swiftinterfaces
2023-10-17 16:41:37 -07:00
Alexis Laferrière
6f1a774e7d [ModuleInterface] Always ignore export-as in private swiftinterfaces
Always print the real module name for references in private
swiftinterfaces, ignoring export-as declarations. Keep using the
export-as name for the public swiftinterface only.

The flag `ModuleInterfaceExportAs` used to enable this behavior and
we're removing it to make it the default.

rdar://115922907
2023-10-16 13:19:55 -07:00
Alexis Laferrière
322ada60c8 [Sema] Intro flag to default imports to internal, the Swift 6 mode
The feature InternalImportsByDefault makes imports default to internal instead
of public. Applying the Swift 6 behavior of SE-0409 in Swift 5.

Let's use only that flag to track the Swift 6 behavior as well instead
of separately checking for the language version.
2023-10-10 09:09:21 -07:00
Alexis Laferrière
3496a74fd9 [ModuleInterface] Print the public keyword on imports in Swift 6 mode
If the access-level on imports proposal is accepted as written, all
imports printed in swiftinterfaces will be `public`. Whether or not we
require the explicit `public` keyword in Swift 6 mode, printing it will
have no downside. It also goes along with the mentality that
swiftinterfaces should be more explicit than implicit.

rdar://115455383
2023-09-14 10:47:37 -07:00
Allan Shortlidge
7c1b150f39 ModuleInterface: Resolve inherited types when computing unsatisfiable conformances.
Previously, unsatisfiable conformances could be omitted from emitted
`.swiftinterface` files in lazy typechecking mode since inherited types might
be unresolved when gathering the conformances.

Adding these test cases also revealed that serialization restrictions needed to
be relaxed in order to accomodate unsatisfiable conformances.
2023-09-07 13:57:39 -07:00
Allan Shortlidge
eee122c093 ModuleInterface: Resolve inherited types when recording indirect conformances.
Previously, indirect public conformances provided by conforming to an internal
protocol could be skipped in a `.swiftinterface` in lazy typechecking mode
since inherited types might not be resolved before collecting the indirect
conformances.
2023-09-07 13:57:39 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -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
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
Allan Shortlidge
0e7ad1e9a4 Frontend: Don't append -target-min-inlining-target target to implicit module builds.
When performing an implicit module build, the frontend was prepending
`-target-min-inlining-target target` to the command line. This was overriding
the implicit `-target-min-inlining-target min` argument that is implied when
`-library-level api` is specified. As a result, the wrong overload could be
picked when compiling the body of an inlinable function to SIL for emission
into the client, potentially resulting in crashes when the client of the module
is back deployed to an older OS.

Resolves rdar://109336472
2023-05-30 13:33:26 -07:00
Ellie Shin
b081404daa Print package-name in .private.swiftinterface only for better abstraction
Resolves rdar://107638447
2023-04-20 17:45:22 -07:00
Alejandro Alonso
c21899ee0f Add BuiltinModule experimental feature 2023-03-28 09:41:37 -07:00
Alexis Laferrière
ab3bf3260f [ModuleInterface] Print the @_spiOnly attribute without comments
This attribute was commented out in the private swiftinterface for
backwards compatibility with older compilers unaware of the attribute.
This scenario shouldn't be a problem anymore and without that attribute
some imports can raise errors. Let's print the attribute as it was
written in the sources without commenting it out.
2023-03-09 15:34:49 -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