Commit Graph

1014 Commits

Author SHA1 Message Date
Doug Gregor
b53026d8d4 [Macros] Macro-metaprogram macro roles
Introduce X-macros for the various macro roles, and use them to
macro-metaprogram a lot of boilerplate involved with introducing new
macro roles.
2023-11-13 22:37:54 -08:00
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Max Ovtsin
b0105e112d Introduce -application-extension-library (#63769)
The current implementation of `-application-extension` has a problem that affects the generation of ObjC headers for regular Swift modules.

The primary purpose of `-application-extension` is to prevent the use of unavailable APIs in app extensions. However, it has an impact on the generation of -Swift.h headers and exposes Swift's internal declarations to ObjC. This behavior is appropriate for mixed modules that are not consumed externally, such as app extensions, but it fails to address the situation when a module is not an extension itself but is consumed by the extension (c90cd11).

To resolve this issue while maintaining the desired behavior, we can introduce a new flag for this particular use-case.
2023-11-03 08:24:19 -07:00
Robert Widmann
17f5864125 Support Clang Module 2023-11-01 16:20:38 -06:00
Robert Widmann
13140df3a4 Weak-Link the Immediate Re-Exports of a Weak-Linked Module
When a module is imported @_weakLinked, its re-exported peer modules
have their definitions imported with strong linkage which can often
defeat the point of weak linking the parent in the first place. Allow
the weak-linkage to float to the immediate re-exports of the @_weakLinked
module.

Resolves rdar://117166194
2023-10-31 22:52:15 -06: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
Mishal Shah
aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Kavon Farvardin
f76360c5b1 [Sema] "Noncopyable" means no Copyable conformance 2023-10-18 13:52:14 -07:00
Kavon Farvardin
d5f2d54ca7 [Sema] initial overhaul of isNoncopyable
This implementation has the function execute a request to scan the
inheritance clause of non-protocol nominals for a `~Copyable`. For
protocols, we look in the requirement signature.

This isn't our final state, as the GenericEnvironment needs to be
queried in general to determine of a Type is noncopyable. So for now
checking for a `~Copyable` only makes sense for Decls.
2023-10-18 13:45:50 -07:00
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
swift-ci
2e9555437f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-29 20:19:54 -07:00
Alexis Laferrière
a0b848ea96 [Sema] Report imports marked as public that are not used in API 2023-09-28 13:00:04 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
swift-ci
dafb784e6a Merge remote-tracking branch 'origin/main' into rebranch 2023-09-14 08:59:47 -07:00
Alexis Laferrière
41e371b175 [Sema] Treat open as we do public for testable and private imports
This should be NFC but will help streamline implementation of
access-level on imports enforcement.
2023-09-12 11:12:30 -07:00
swift-ci
5bb21c1303 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-07 01:14:42 -07:00
Kuba Mracek
25eb997a28 [embedded] Add basics of module serialization, importing and validation in embedded Swift.
- Add a flag to the serialized module (IsEmbeddedSwiftModule)
- Check on import that the mode matches (don't allow importing non-embedded module in embedded mode and vice versa)
- Drop TBD support, it's not expected to work in embedded Swift for now
- Drop auto-linking backdeploy libraries, it's not expected to backdeploy embedded Swift for now
- Drop prespecializations, not expected to work in embedded Swift for now
- Use CMO to serialize everything when emitting an embedded Swift module
- Change SILLinker to deserialize/import everything when importing an embedded Swift module
- Add an IR test for importing modules
- Add a deserialization validation test
2023-09-06 20:06:36 -07:00
Zak Kent
2abca625d7 Merge branch 'main' into update-immediate 2023-08-18 16:07:14 -07:00
zachary0kent
25f078adb5 Merge branch 'main' into lazy-immediate 2023-08-16 19:45:27 -07:00
Zak Kent
831cfb575d [Sema] [NFC] Don't accumulate lazily typechecked functions in lazy immediate mode 2023-08-16 19:30:31 -07:00
swift-ci
73cf37d597 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 17:33:42 -07:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
swift-ci
b87613bace Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 04:34:00 -07:00
Slava Pestov
c26cafc47a AST: Remove bogus PackExpansionType logic in lookupConformance() 2023-08-09 18:28:22 -04:00
Slava Pestov
f219274e9b AST: Remove generic signature and conditional requirements from BuiltinProtocolConformance 2023-08-09 17:42:57 -04:00
Slava Pestov
9f51ea1de6 AST: Remove old tuple conformance logic from getBuiltinTupleTypeConformance() 2023-08-09 17:42:25 -04:00
Slava Pestov
e6d611cda3 AST: Pass allowMissing=true from getPackTypeConformance() 2023-08-09 17:42:25 -04:00
swift-ci
6fa99b78cf Merge remote-tracking branch 'origin/main' into rebranch 2023-08-08 22:14:47 -07:00
Allan Shortlidge
c3af951f38 AST: Get SPI status of PatternBindingDecl from anchoring VarDecl.
For property declarations, the `@_spi` attribute is attached to the VarDecl AST
node, rather than the PatternBindingDecl AST node, so the `isSPI()` query
should take this into account. Failing to do so caused the availability checker
to erroneously require that `@_spi` properties of types in `-library-level api`
libraries have availability annotations.

Resolves rdar://113587321.
2023-08-08 16:06:36 -07:00
Becca Royal-Gordon
3eebc6dddb Merge branch 'main' into rebranch
# Conflicts:
#	lib/SILOptimizer/Differentiation/Common.cpp
2023-08-04 15:09:50 -07:00
Alexis Laferrière
69493d1f4a [Sema] @_private imports brings is all SPI of the imported module
Within one module, SPI decls are always visible. Conceptually we want
the same behavior for `@_private` imports where the client pretends it's
part of the same module.

rdar://81240984
2023-08-04 10:30:36 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Sophia Poirier
974081c065 [Variadic Generics] abstract tuple of Sendable elements does not conform to Sendable 2023-07-19 12:35:01 -07:00
Doug Gregor
8df508c453 Merge pull request #67105 from DougGregor/freestanding-macro-global-scope-in-scripts 2023-07-04 12:17:47 -07:00
Doug Gregor
939376b61e [Macros] Enable freestanding macros at module scope in script mode
Eliminate the error message

    error: global freestanding macros not yet supported in script mode

by implementing name lookup, type checking, and code emission for
freestanding macros. The key problem here is that, in script mode,
it is ambiguous whether a use of a freestanding macro is an expression
or a declaration. We parse as an expression (as we do within a
function body), which then gets wrapped in a top-level code
declaration.

Teach various parts of the compiler to look through a top-level code
declaration wrapping a macro expansion expression that is for a
declaration or code-item macro, e.g., by recording these for global
name lookup and treating their expansions as "auxiliary" declarations.

Fixes rdar://109699501.
2023-07-03 21:00:51 -07:00
Holly Borla
0bd898eb12 [Macros] Allow extension macros to suppress conformances that are already
stated in the original source.

If an extension macro can introduce protocol conformances, macro expansion
will check which of those protocols already have a stated conformance in the
original source. The protocols that don't will be passed as arguments to
extension macro expansion, indicating to the macro that it should only add
conformances to those protocols.
2023-06-30 16:01:15 -07:00
Slava Pestov
5ce14265e4 Fix some random compiler warnings 2023-06-29 16:29:10 -04:00
Holly Borla
7a46466b65 Merge pull request #66967 from hborla/extension-macro
[Macros] Generalize `conformance` macros as `extension` macros
2023-06-29 08:57:04 -07:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -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
da8e84caac Merge pull request #66914 from hborla/conformance-macro-in-extension
[Macros] Don't visit macro-generated extensions in `visitAuxiliaryDecls`.
2023-06-26 15:45:03 -07:00
Holly Borla
83030a9c63 [Macros] Don't visit macro-generated extensions in 'visitAuxiliaryDecls'.
Macro-generated extensions are hoisted to file scope, because extensions are
not valid in nested scopes. Callers of 'visitAuxiliaryDecls' assume that the
auxiliary decls are in the same decl context as the original, which is clearly
not the case for extensions, and it leads to issues like visiting extension at
the wrong time during SILGen. The extensions are already added to the top-level
decls, so we don't need to visit them as auxiliary decls, and we can type-check
macro-expanded decls at the end of visitation in TypeCheckDeclPrimary.
2023-06-23 23:25:32 -07:00
Rintaro Ishizaki
096d8ea142 [CodeCompletion] Suggest synthesized declarations from macros
* Don't invalidate the lookup cache in 'getOrCreateSynthesizedFile()'
  Adding a synthesized file itself doesn't introduce any decls. Instead,
  we should invalidate the right after the actual declrations are added
  in the file
* Remove 'SourceLookupCache::invalidate()' method. It was just used
  right before the destruction. It was just not necessary
* Include auxiliary decls in 'SourceLookupCache::lookupVisibleDecls()'
  Previously, global symbol completion didn't include decls synthesized
  by peer macros or freestanding decl macros
* Include "auxiliary decls" in visible member lookup, and visible local
  decl lookup
* Hide macro unique names

rdar://110535113
2023-06-22 13:18:46 -07:00
Ben Barham
ee3a47b624 [Frontend] Ignore adjacent swiftmodule in compiler host modules
`lib/swift/host` contains modules/libraries that are built by the host
compiler. Their `.swiftmodule` will never be able to be read, ignore
them entirely.
2023-06-12 16:53:48 -07:00
Alex Lorenz
ba8d4d7801 [cxx-interop] compilations that do not enable C++ interoperability should not be able to import modules that do enable C++ interoperability by default
A supplemental hidden frontend option allows advanced users to opt-out of this requirement.

Fixes https://github.com/apple/swift/issues/65833
Fixes https://github.com/apple/swift/issues/65832
2023-06-09 15:38:16 -07:00