Commit Graph

572 Commits

Author SHA1 Message Date
Alexis Laferrière
8fefdece2c Use a SetVector when looking up the SPI attributes on imports
Using a SetVector fixes an issue where many source files imported the
same SPI group from the same module, the emitted private textual
interfaces superfluously repeated the `@_spi` attribute on the import.

rdar://problem/63681845
2020-05-27 16:11:12 -07:00
Robert Widmann
a5dcb1d400 [NFC] Add a "Main Module" Bit
The constraint system will need this if it wants to disable debug mode for serialized modules
2020-05-13 09:13:44 -07:00
Robert Widmann
22d657c9a5 Merge pull request #31639 from CodaFi/it-could-happen
Patch a Source of Iterator Invalidation
2020-05-08 09:41:31 -07:00
Slava Pestov
3ee2409890 SIL: Use ASTScope for SIL parsing 2020-05-08 00:31:23 -04:00
Robert Widmann
035cecaaa4 Patch a Source of Iterator Invalidation
getOpaqueResultTypeDecl() can wind up invoking lazy function body
parsing when it runs availability checking. If any of those function
bodies have opaque result types, they will be inserted. If that
insertion happens to resize the SetVector, iterators will be invalidated
and a non-deterministic crash results.

Instead, use SetVector::takeVector() for the iteration so we have
a temporary copy whose iterators cannot be invalidated in this
situation. This also elegantly handles clearing out the vector for us.

Resolves rdar://62976771
2020-05-07 14:22:35 -07:00
Slava Pestov
b81c0d63d1 AST: Remove SourceFileKind::REPL 2020-05-07 02:04:05 -04:00
Daniel Sweeney
ea526c6383 Converting ModuleDecl::ImportedModule from std::pair to a dedicated struct. (#31360) 2020-04-30 20:26:03 -07:00
Hamish Knight
22c64640e0 Register operator dependencies on direct lookup requests
Make sure a dependency gets registered when a
direct lookup is fired off. This is necessary in
order to ensure that operator redeclaration
checking records the right dependencies (and any
future logic that might want to perform direct
operator lookups).

In doing so, this commit also removes the
compatibility logic for the old referenced name
tracker that would skip recording dependencies in
certain cases. This should be safe as the new
logic will record strictly more dependencies than
the old logic.
2020-04-30 15:27:51 -07:00
Robert Widmann
1f5dcf0269 Merge pull request #31229 from CodaFi/collect-a-mundo
[NFC] Extract Dependency Registration to DependencyCollector
2020-04-30 13:53:44 -07:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Nathan Hawes
b7ac8f87b1 [IDE][AST] Handle frameworks with traditional overlays where the underlying module declares cross imports in sourcekit.
We weren't handling this case, so their generated interfaces / doc info
wouldn't include symbols from the cross-import overlays, and we wouldn't
map the underscored cross-import overlay name back to the declaring
framework's name in cusor-info, completion results or when indexing.

Resolves rdar://problem/62138551
2020-04-23 13:03:59 -07:00
Robert Widmann
7a724b1477 [NFC] Extract Dependency Registration to DependencyCollector
Define a new type DependencyCollector that abstracts over the
incremental dependency gathering logic. This will insulate the
request-based name tracking code from future work on private,
intransitive dependencies.
2020-04-22 21:01:20 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Brent Royal-Gordon
4619e2eee6 Merge pull request #31199 from brentdax/pathfinder
Fix layering of cross-import and clang overlays
2020-04-22 16:37:28 -07:00
nate-chandler
a41a2ffb7e Merge pull request #30693 from nate-chandler/main-attribute
@main: Attribute to add an entry point to a type.
2020-04-22 15:42:49 -07:00
Robert Widmann
78e07c1d41 Merge pull request #31159 from CodaFi/track-star
Remove Fallback Infrastructure For Evaluator-Based Dependencies
2020-04-22 15:37:48 -07:00
Brent Royal-Gordon
d4eabeb4b1 [NFC] Add dumper for separately-imported overlays 2020-04-21 23:39:03 -07:00
Hamish Knight
76ec21fd0e Requestify hasImplementationOnlyImports
Add HasImplementationOnlyImportsRequest to
compute whether a file has any implementation-only
imports.
2020-04-20 20:04:56 -07:00
Hamish Knight
92103a7c63 [AST] Remove SourceFile::addImports
Temporarily replace with `SourceFile::setImports`
until import resolution is requestified. Now
imports are only set once for a given SourceFile.

Because we're now asserting in more places that
import resolution must have run before querying
imports, this commit also adds
`getCachedUnderlyingType` to TypeAliasDecl to stop
the ASTDumper from trying to query imports for a
-dump-parse invocation.
2020-04-20 13:20:35 -07:00
Hamish Knight
7f8a0e8a6c Requestify implicit imports
Add ModuleImplicitImportsRequest, which computes
the modules that should be implicitly imported by
each file of a given module. Use this request in
import resolution to add all the necessary
implicit imports.

The request computes the implicit imports by
consulting the ImplicitImportInfo, which ModuleDecl
can now be created with. This allows us to remove
uses of `SourceFile::addImports` in favor of
adding modules needed to be implicitly imported to
the ImplicitImportInfo.
2020-04-20 13:20:35 -07:00
Robert Widmann
94166024fa Dump all uses of the legacy referenced name tracker 2020-04-20 10:22:58 -07:00
Dan Zheng
d28cf1cf55 [IRGen] Fix SynthesizedFileUnit. (#31082)
SynthesizedFileUnits are attached to a SourceFile.

Make IRGen consistent with TBDGen: when processing a SourceFile, only process
the attached SynthesizedFile. This avoids IRGen/TBDGen inconsistencies.

Use SourceFile name in SynthesizedFileUnit::getDiscriminatorForPrivateValue.

Resolves TF-1249.
2020-04-17 15:49:36 -07:00
Nate Chandler
df99de804d Added executable entry-point via @main type.
When a type (class, enum, or struct) is annotated @main, it is required
to provide a function with the following signature:

  static func main() -> ()

That function will be called when the executable the type is defined
within is launched.
2020-04-17 09:53:46 -07:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Dan Zheng
165af547f3 Fix SynthesizedFileUnit serialization and TBDGen issues.
Make `SynthesizedFileUnit` attached to a `SourceFile`. This seemed like the
least ad-hoc approach to avoid doing unnecessary work for other `FileUnit`s.

TBDGen: when visiting a `SourceFile`, also visit its `SynthesizedFileUnit` if
it exists.

Serialization: do not treat `SynthesizedFileUnit` declarations as xrefs when
serializing the companion `SourceFile`.

Resolves TF-1239: AutoDiff test failures.
2020-04-08 21:19:56 -07:00
Brent Royal-Gordon
4de19e1c3c Merge pull request #30819 from brentdax/a-less-ambitious-crossover-event
Ignore transitive ObjC imports when cross-importing
2020-04-08 11:40:35 -07:00
Dan Zheng
f7a9eed4de [AutoDiff] Add generated implicit declarations to SynthesizedFileUnit.
Add implicit declarations generated by the differentiation transform to a
`SynthesizedFileUnit` instead of an ad-hoc pre-existing `SourceFile`.

Resolves TF-1232: type reconstruction for AutoDiff-generated declarations.

Previously, type reconstruction failed because retroactively adding declarations
to a `SourceFile` did not update name lookup caches.
2020-04-07 18:29:34 -07:00
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Dan Zheng
f9ef75ff34 Remove SourceFile::addVisibleDecl.
`SourceFile::addVisibleDecl` is an unnecessary API.
It was upstreamed in https://github.com/apple/swift/pull/30821.
2020-04-07 13:19:55 -07:00
Dan Zheng
8081482b57 [AutoDiff upstream] Add common SIL differentiation utilities. 2020-04-05 20:35:35 -07:00
Brent Royal-Gordon
121fa9a058 Ignore transitive ObjC imports when cross-importing
This behavior change reduces the chance of unexpected and unwanted cross-imports being performed.

Fixes rdar://problem/60554019.
2020-04-05 19:06:59 -07:00
Nathan Hawes
9f6f76308e Add method to ModuleDecl to lazily compute the underlying module for cross-import overlays
Also update code completion, indexing, interface generation and doc info to use it.
2020-04-03 16:04:32 -07:00
Robert Widmann
42cfc7eb58 Add "Legacy" to the manual referenced name tracker 2020-03-31 16:16:53 -07:00
Robert Widmann
2b0ca2ae65 Add the active tracker to the dependency sink points 2020-03-31 16:16:53 -07:00
Robert Widmann
8c69814f5c Define Dependency Sinks
Convert most of the name lookup requests and a few other ancillary typechecking requests into dependency sinks.

Some requests are also combined sinks and sources in order to emulate the current scheme, which performs scope changes based on lookup flags. This is generally undesirable, since it means those requests cannot immediately be generalized to a purely context-based scheme because they depend on some client-provided entropy source. In particular, the few callers that are providing the "known private" name lookup flag need to be converted to perform lookups in the appropriate private context.

Clients that are passing "no known dependency" are currently considered universally incorrect and are outside the scope of the compatibility guarantees. This means that request-based dependency tracking registers strictly more edges than manual dependency tracking. It also means that once we fixup the clients that are passing "known private", we can completely remove these name lookup flags.

Finally, some tests had to change to accomodate the new scheme. Currently, we go out of our way to register a dependency edge for extensions that declare protocol conformances. However, we were also asserting in at least one test that extensions without protocol conformances weren't registering dependency edges. This is blatantly incorrect and has been undone now that the request-based scheme is automatically registering this edge.
2020-03-31 16:16:53 -07:00
Robert Widmann
a337b67f69 Stage In Flags To Fall Back To Manual Tracking
Request-based incremental dependencies are enabled by default. For the time being, add a flag that will turn them off and switch back to manual dependency tracking.
2020-03-31 16:16:53 -07:00
Robert Widmann
92c8a65f09 Drop references to name binding as a phase
A lot of places appear to mean "name lookup".  A few places meant "import resolution".
2020-03-29 18:51:09 -07:00
Hamish Knight
d2434e1bf7 NFC: Rename NameBinding to ImportResolution 2020-03-29 18:43:58 -07:00
Hamish Knight
4e42f033a5 Switch operator lookup over to using SourceLookupCache
Switch the direct operator lookup logic over to
querying the SourceLookupCache, then switch the
main operator lookup logic over to calling the
direct lookup logic rather than querying the
operator maps on the SourceFile.

This then allows us to remove the SourceFile
operator maps, in addition to the logic from
NameBinding that populated them. This requires
redeclaration checking to be implemented
separately.

Finally, to compensate for the caching that the old
operator maps were providing for imported results,
turn the operator lookup requests into cached
requests.
2020-03-27 09:45:33 -07:00
Hamish Knight
6f212634c8 Add getOperatorDecls to FileUnit and ModuleDecl
Query the SourceLookupCache for the operator decls,
and use ModuleDecl::getOperatorDecls for both
frontend stats and to clean up some code
completion logic.

In addition, this commit switches getPrecedenceGroups
over to querying SourceLookupCache.
2020-03-27 09:44:55 -07:00
Hamish Knight
6c3362fb55 Add precedencegroup and operator decls to SourceLookupCache 2020-03-27 09:44:55 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Alexis Laferrière
8c61335045 Merge pull request #30661 from xymus/fix60819771
Protect against erroneous extensions in `SPIGroupsRequest`
2020-03-26 19:36:00 -07:00
Alexis Laferrière
56c5959872 [SPI] Protect against an erroneous extension
rdar://problem/60819771
2020-03-26 12:51:03 -07:00
Nathan Hawes
8b03b05f1d [Index] Add index support for cross import overlays.
Resolves rdar://problem/59445445
2020-03-25 10:04:41 -07:00
Nathan Hawes
7811f531cb Merge pull request #30521 from nathawes/cross-import-interface-gen
[SourceKit/InterfaceGen] Also print the cross-import overlays of a module in its interface.
2020-03-24 10:28:55 -07:00
Robert Widmann
d4bc0a62c5 [NFC] Define LookupConformanceInModuleRequest
Factor out the lookup side of TypeChecker::conformsToProtocol so we have
a dependency registration point available for evaluator-based
dependencies that doesn't have re-entrancy problems.
2020-03-23 16:24:17 -07:00
Hamish Knight
cc9c851856 Add direct operator lookup requests
Introduce DirectOperatorLookupRequest &
DirectPrecedenceGroupLookupRequest that lookup
operator and precedence groups within a given
file or module without looking through imports.

These will eventually be used as the basis for the
new operator lookup implementation, but for now
just use them when querying lookup results from
serialized module files.
2020-03-23 09:17:58 -07:00
Hamish Knight
9656a0491e Allow OperatorLookupDescriptor to hold a file or module 2020-03-23 09:17:58 -07:00
Hamish Knight
a502246f34 [AST] Add OperatorFixity
Use this instead of DeclKind in a few places.
2020-03-23 09:17:58 -07:00