Commit Graph

1003 Commits

Author SHA1 Message Date
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
Doug Gregor
343947a532 [Module-scope lookup] Don't expand macros associated with members of types
The module-scope lookup tables use the same code for adding
module-scope declarations as for adding member operators, which are
found via "global" operator lookup. This requires us to expand macros
that can produce members of types, which violates the outside-in
expansion rule described in the proposals.

Stop recording member-producing macros, whether they are peer macros
applied to member declarations or are freestanding declaration macros
within a member context. This re-establishes the outside-in expansion
rule. It also means that member operators introduced by macro
expansion won't be found by global operator lookup, which is a
(necessary) semantic change.
2023-06-03 23:06:29 -07:00
Doug Gregor
ebe0b63c5e [Module-scope lookup] Only inject macro-introduced operators at module scope
Well, this is fun. Due to the use of the module-scope lookup table to
find operators, we need to carefully filter out any macro-introduced
declarations that *aren't* operators when forming the module-scope
lookup table. Otherwise, we can find macro-introduced static entities
within types... from completely unrelated scopes.

Fixes rdar://109219036.
2023-06-02 23:55:55 -07:00
Ellie Shin
32f53d1eb8 Add implicit SPI import feature
API development sometimes requires a redesign while supporting early
adopters. Currently this is done by adding @_spi(name) to the API but
that requires adding the attribute in import statements as well, causing
manual overhead of adding and then removing when the redesign is done.

This PR introduces a special spi group name '_' and allows an implicit
spi import of a module containing API attributed with '@_spi(_)'

Resolves rdar://109797632
2023-06-01 15:33:04 -07:00
Hamish Knight
58d6694783 Requestify ExportedSourceFile parsing
Avoid parsing the syntax tree up-front, and instead
only parse it when required, which happens when either:

1. ASTGen parsing is enabled (currently disabled
   by default)
2. Round trip checking is enabled for a primary
   file (enabled by default in a debug build,
   except when dep scanning or doing an IDE
   operation)
3. We need to evaluate a macro in that file

This change therefore means that we now no longer
need to parse the syntax tree for secondary files
by default unless we specifically need to evaluate
a macro in them (e.g if we need to lookup a member
on a decl with an attached macro). And the same
for primaries in release builds.

rdar://109283847
2023-05-22 14:55:19 +01:00
Kavon Farvardin
103bd043cd Revert "Revert "Prevent noncopyable metatypes from being converted to Any""
This reverts commit 1a3b42cd63.
2023-05-04 11:38:00 -07:00
Hamish Knight
1a3b42cd63 Revert "Prevent noncopyable metatypes from being converted to Any" 2023-05-04 12:10:10 +01:00
Kavon Farvardin
1df3912794 Merge pull request #65606 from kavon/noncopyable-metatypes
Prevent noncopyable metatypes from being converted to `Any`
2023-05-03 22:05:17 -07:00
Kavon Farvardin
4710fc675b Prevent noncopyable metatypes from being converted to Any
These metatypes are a gateway to more incorrect
uses of these noncopyable values because we don't
yet have the corresponding runtime support yet.
The other use cases of using metatypes of
noncopyable types in generics is not high enough to
warrant people using them yet.

resolves rdar://106452518
2023-05-03 10:23:11 -07:00
Doug Gregor
7c4547ff82 Only synthesize a private discriminator when needed 2023-04-27 16:15:26 -07:00
Doug Gregor
0eb095b32c [Macros] Use private discriminators for expression macros
Expression macros ascribed to non-private contexts need private
discriminators so they don't conflict with other uses of the same macro
in other source files.

Thank you, Richard, for noticing this omission!
2023-04-27 14:30:17 -07:00
Hamish Knight
c1843479f1 Drop SerializedOK parameter from getRawComment
It doesn't seem like there's any client that's
actually taking advantage of setting it to `false`,
and its default value of `false` is more likely
than not going to cause clients to accidentally
miss comments that they may want. In fact, this
was exactly the case for code completion's brief
field. Finally, the parameter wasn't even
consistently applied, as we would attempt to
deserialize swiftdoc comments even if it were
`false`.
2023-04-26 12:38:37 +01:00