Commit Graph

742 Commits

Author SHA1 Message Date
Alexis Laferrière
82e93806a8 [Sema] Force considering the __ObjC module as imported publicly 2022-07-07 14:57:00 -07:00
Alexis Laferrière
9127f90d8d [Sema] Report uses of implicitly imported decls in inlinable code
Implicitly imported decls may end up in inlinable code and break the
module API. This have been known to lead to deserialization crash and
could in theory break the generated swiftinterfaces files. Let's
explicitly check for such a case, keeping it to a warning until Swift 6
where we can make it an error.

rdar://95816286
2022-06-29 16:09:42 -07:00
Alexis Laferrière
4c995a3a87 [Sema] Generalize isImplementationOnlyImported
Renaming isImportedImplementationOnly to getRestrictedImportKind will
allow us to support different kind of restrictive imports in the next
commits.
2022-06-29 16:09:42 -07:00
Slava Pestov
bd46bdaaaa AST: Narrow the filtering of unavailable conformances to Sendable only
Remove the allowUnavailable parameter to lookupConformance(), and instead
explicitly check the result for hasUnavailableConformance() in the places
where we used to pass 'false'.

Also, narrow down this check in those places to the Sendable protocol
only, fixing a regression with Hashable conformance synthesis.

Fixes rdar://problem/94460143.
2022-06-14 21:24:08 -04:00
Robert Widmann
0d117c1345 Don't Mutate ModuleDecl's File List When Creating Synthesized Files
See #59144 for more on why this is a bad idea.

Patch out the synthesized file unit accessor to only clear the source cache, then patch up all the places that were assuming they could iterate over the module's file list and see synthesized files.

rdar://94164512
2022-06-11 11:07:05 -06:00
Robert Widmann
bbe4608fa4 Patch Out a Source of Iterator Invalidation
Synthesized file units were designed for autodiff to emit synthesized declarations, and also to sidestep the design implications of doing so late in the compiler pipeline.

A call to materialize synthesized file units was added to the GetImplicitSendable request. This introduced a source of iterator invalidation into forEachFileToTypeCheck in whole-module builds. Any call to insert a new file into the module has the potential to cause the underlying SmallVector to reallocate.

This patch provides a narrow workaround that stops using iterators altogether in forEachFileToTypeCheck. However, this bug reveals a severe architectural flaw in the concept of a synthesized file unit. Iterating over the files in a module is an extremely common operation, and there now are myriad ways we could wind up calling a function that mutates the module's list of files in the process. This also means the number and kind of files being visited by compiler analyses is dependent upon whether a request that inserts these files has or has not been called.

This suggests the call to ModuleDecl::addFile in FileUnit::getOrCreateSynthesizedFile is deleterious and should be removed. Doing so will come as part of a larger refactoring.

rdar://94043340
2022-05-28 12:37:24 -07:00
Doug Gregor
c9c50b4ae0 [Requirement machine] Ignore unavailable conformances on superclass constraints.
When determining whether a superclass conforms to a particular protocol,
skip unavailable conformances. This way, we don't minimize away a
constraint that might only apply to subclasses of the specified
superclass.

Fixes rdar://91853658.
2022-05-27 13:09:15 -07:00
Ben Barham
4a4dded2fc [IDE] Skip walking serialized non-visible extension decls
fec7a0b79b skipped all non-visible
`ValueDecls` but missed `ExtensionDecls`, which have the same issue.
Make sure to skip these too.

Resolves rdar://91279771.
2022-05-23 11:40:41 -07:00
Doug Gregor
8c3d1fb2ca Make sure we don't provide duplicate synthesized conformance table entries.
This was benign with `Sendable`, but is not benign for the `Encodable`
and `Decodable` synthesis for distributed actors, which results in a
crash in TBD generation.

Fixes rdar://92008955.
2022-04-22 15:41:01 -07:00
Alexis Laferrière
29cd5518fa Merge pull request #42432 from xymus/consider-more-paths-as-spi
[Sema] Consider more paths in the SDK as defining private modules
2022-04-18 17:47:44 -07:00
Alexis Laferrière
91001f0257 [Sema] Consider modules imported from more paths as private
Consider both frameworks and free floating modules imported from more
private path as SPI. This will make the compiler raise errors on public
imports of more private modules.

rdar://91904154
2022-04-18 14:37:48 -07:00
Alexis Laferrière
fb155133a3 [Sema][NFC] Refactor the logic matching paths in the SDK 2022-04-18 14:36:53 -07:00
Ben Barham
fec7a0b79b [IDE] Skip walking serialized internal top level decls in SemaAnnotator
`SemaAnnotator` always attempts to retrieve the location of the decl. This
requires generating the USR, which needs to resolve the type. But that's
invalid in the presence of `@_implementationOnly`.

This most commonly comes up during index while building as even though
it skip internal decls, by that point it's too late (`SemaAnnotator` has
already tried retrieving the location). Other uses of
`SourceEntityWalker` should be unaffected as they only run over the
current decls in the current module.

For now skip walking internal top level decls from serialized modules in
`SemaAnnotator`. Consider expanding this to most, if not all,
`ASTWalker` clients in the future - it's unlikely `SemaAnnotator` is the
only one with this problem.

Resolves rdar://91279771.
2022-04-15 17:08:47 -07:00
John McCall
5519749ade [NFC] Collect protocol decls, not type, in ExistentialLayout
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
2022-04-11 22:15:16 -04:00
Konrad `ktoso` Malawski
b86bb0ddeb fix require-explicit-sendable 2022-03-11 18:07:14 +09:00
Konrad `ktoso` Malawski
6d502fc042 [Distributed] Implicit Codable conformance for Dist Actors
[Witness] implement dump() on witness
2022-03-11 18:07:14 +09:00
Franklin Schrans
9cd44ca5d1 [SymbolGraphGen] Emit symbols from exported modules
When emitting a symbol graph file for a module that import modules via
`@_exported import`, emits those modules' symbols as well.

SR-15753

rdar://89547374
2022-02-28 17:21:25 +00:00
Victoria Mitchell
cab1669e09 only recurse getDisplayDecls in SymbolGraphGen 2022-02-19 10:32:29 -07:00
QuietMisdreavus
036d78f6ad Merge pull request #41115 from apple/QuietMisdreavus/duplicate-clang-syms
skip implicit clang decls in the duplicate-decl assertion

SR-15801
2022-02-19 10:30:53 -07:00
Victoria Mitchell
46f6b72ed6 skip implicit clang decls in the duplicate-decl assertion
SR-15801

rdar://88299954
2022-01-31 18:17:34 -07:00
Evan Wilde
3b90b08582 Use presence of 'await' to make top-level async
To help maintain source-compatibility, the presence of an `await` in
top-level code to kick the top-level code over to being a concurrent
context.

This, of course, means that in the test cases that exist today, they
will go back to behaving identically to how they did before I added all
of this because they don't have any awaits in the top-level. I'll be
adding new tests to verify the differences in behavior between swift 5,
swift 6, with and without async top level enabled in the next commit.
2022-01-28 07:55:14 -08:00
Doug Gregor
7149702d12 Rename @_predatesConcurrency to @preconcurrency.
Introduce the `@preconcurrency` attribute name for `@_predatesConcurrency`,
which has been the favored name in the pitch thread so far. Retain the
old name for now to help smooth migration.
2022-01-26 08:39:01 -08:00
Victoria Mitchell
aeaf6b22db [AST] check modules before recursing for display decls 2022-01-18 08:51:29 -07:00
Victoria Mitchell
ec6c3fb3d7 Revert "Merge pull request #40877 from apple/revert-40810-QuietMisdreavus/sourcefile-export"
This reverts commit caf2f087e3, reversing
changes made to 5a9abb2119.
2022-01-18 08:51:10 -07:00
Mishal Shah
caf2f087e3 Merge pull request #40877 from apple/revert-40810-QuietMisdreavus/sourcefile-export
Revert "[AST] scan `@_exported import` modules of source files for display decls"
2022-01-16 21:45:20 -08:00
nate-chandler
05a4c57149 Revert "[AST] scan @_exported import modules of source files for display decls" 2022-01-14 09:10:34 -08:00
Holly Borla
f368b77ad5 [Sema] Account for ExistentialType in lookupExistentialConformance. 2022-01-13 19:30:44 -08:00
Victoria Mitchell
e04092d87e don't crawl exported imports more than once 2022-01-13 09:01:52 -07:00
Victoria Mitchell
1f7fe0220a SourceFile::getDisplayDecls also walks @_exported imports 2022-01-13 09:01:52 -07:00
Victoria Mitchell
b5dc995d3e add module/file debug dumpers 2022-01-13 09:01:52 -07:00
Doug Gregor
5023a934fc Tolerate missing Sendable conformances on superclasses.
Fixes the crash in rdar://86653457
2022-01-11 11:11:21 -08:00
Doug Gregor
2832aedfe2 Make the @_predatesConcurrency diagnostic a once-per-file-per-module remark
Rather than tacking the "add `@_predatesConcurrecy` to import"
diagnostic on to the prior diagnostic as a note, make it its own
remark. Then, ensure that we only emit this remark once per source
file per imported module, so we're not overwhelming the user.
2021-12-21 12:16:06 -08:00
Alex Hoppen
669e3f34a6 Merge pull request #40155 from ahoppen/pr/improve-module-search-path-lookup
[Serialization] Improve module loading performance
2021-12-20 18:09:17 +01:00
Erik Eckstein
408cf02bc8 rework cross-module-optimization
* rename the CrossModuleSerializationSetup pass to simply CrossModuleOptimization
* remove the CMO specific serializer pass. Instead run the CrossModuleSerializationSetup pass directly before the standard serializer pass.
* correctly handle shared functions (e.g. specializations)
* refactoring
2021-12-20 11:33:02 +01:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Ellie Shin
d95d0a0a7d Merge pull request #40450 from apple/es-index
[Indexing] If module aliasing is used, store module real names to index unit/record files
Resolves rdar://82896373
2021-12-07 23:49:01 -08:00
Ellie Shin
0ff713d44c [Indexing] Use module real name in case module aliasing is used
Resolves rdar://82896373
2021-12-07 02:22:36 -08:00
Xi Ge
6377c3a742 Revert "Revert "serialization: obfuscate the serialized search paths"" 2021-12-02 13:21:04 -08:00
Saleem Abdulrasool
11d5d6d4ca Revert "serialization: obfuscate the serialized search paths" 2021-12-02 08:18:23 -08:00
Xi Ge
0047d81f9a serialization: obfuscate the serialized search paths
We noticed some Swift clients rely on the serialized search paths in the module to
find dependencies and droping these paths altogether can lead to build failures like
rdar://85840921.

This change teaches the serialization to obfuscate the search paths and the deserialization
to recover them. This allows clients to keep accessing these paths without exposing
them when shipping the module to other users.
2021-12-01 11:47:41 -08:00
Kuba (Brecka) Mracek
c89eca6c34 Enforce consistent usage of -experimental-hermetic-seat-at-link flag (#39986)
We've recently added the -experimental-hermetic-seal-at-link compiler flag,
which turns on aggressive dead-stripping optimizations and assumes that library
code can be optimized against client code because all users of the library
code/types are present at link/LTO time. This means that any module that's
built with -experimental-hermetic-seal-at-link requires all clients of this
module to also use -experimental-hermetic-seal-at-link. This PR enforces that
by storing a bit in the serialized module, and checking the bit when importing
modules.
2021-11-30 10:44:58 -08:00
Becca Royal-Gordon
1880118e70 Restructure getDisplayDecl() Sendable forcing
Move this into a helper function that lives in Sema, avoiding libswiftAST calling into libswiftSema.
2021-11-19 17:51:27 -08:00
Becca Royal-Gordon
8007d70659 Print Sendable conformances for clang types 2021-11-19 11:34:01 -08:00
Becca Royal-Gordon
21f58ec78f [NFC] Attach SynthesizedFile to any FileUnit
Gives us a place to stuff synthesized declarations for, among other things, imported Clang decls.
2021-11-19 11:34:01 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00
Becca Royal-Gordon
36bae62b19 Print Sendable conformances for clang types 2021-11-12 23:13:29 -08:00
Becca Royal-Gordon
e130826686 [NFC] Attach SynthesizedFile to any FileUnit
Gives us a place to stuff synthesized declarations for, among other things, imported Clang decls.
2021-11-12 23:13:29 -08:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Ellie Shin
6f34844b49 Merge pull request #39705 from apple/es-module-alias-serialize
[Module aliasing] Serialize SIL and binaries with module real names for referenced or imported modules. Resolves rdar://83632529
2021-10-18 21:55:45 -07:00
Becca Royal-Gordon
fa8436bdf6 [NFC] Allow extensions in SynthesizedFileUnits 2021-10-14 12:14:46 -07:00