Commit Graph

757 Commits

Author SHA1 Message Date
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
Hamish Knight
e5952ab7fe Fix a couple of invalid location diagnostics 2020-03-23 09:17:58 -07:00
Robert Widmann
425bd50f76 [Gardening] Remove some parameters obviated by OperatorLookup::map_ptr 2020-03-21 11:34:52 -07:00
Robert Widmann
c136a0b190 [NFC] Remove SourceFile's Operator Lookup Entrypoints
Now that this is requestified, the extra level of indirection serves no
purpose.
2020-03-21 11:19:46 -07:00
Nathan Hawes
a7e1cb3925 [SourceKit] Update cursor info to report symbols from cross-import overlays as coming from the underylying module.
Also refactor some of the interface generation cross-import support code to be
shared.
2020-03-20 21:49:51 -07:00
Robert Widmann
bfe23bba5b Define LookupOperatorRequest and Friends
Turn macro metaprogramming into template metaprogramming by defining a new kind of request that runs operator lookups.

This is the final piece of the puzzle for requestification of the current referenced name tracker system.
2020-03-20 15:50:12 -07:00
Nathan Hawes
fd82d87db0 Merge pull request #30402 from nathawes/cross-import-code-completion
[IDE/CodeCompletion] Add code completion support for cross import overlays.
2020-03-18 18:16:03 -07:00
Nathan Hawes
63636100be [IDE/CodeCompletion] Add code completion support for cross import overlays.
If a cross-import overlay shadows another module and has a name starting with
'_', don't present that overlay in places where module name completions are
offered and present symbols comining from that module as if they came from
the shadowed module instead.

Resolves rdar://problem/59445688
2020-03-18 12:02:20 -07:00
swift-ci
3fa4840561 Merge pull request #30395 from brentdax/two-revisions-for-two-revisions-for-slashing 2020-03-17 14:11:02 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Brent Royal-Gordon
0be8357dcc Merge pull request #29950 from brentdax/less-crossover
Make cross-importing faster
2020-03-13 01:45:02 -07:00
Brent Royal-Gordon
b65a9c6db1 [NFC] Doc and style fixes for #filePath implementation
This addresses some late-breaking review comments left by @hamishknight on apple/swift#29412.
2020-03-12 18:12:09 -07:00
Brent Royal-Gordon
d590823f3c Warn about conflicts between #file strings 2020-03-05 23:30:37 -08:00
Brent Royal-Gordon
8e5ca8abdf [NFC] Generate #file -> #filePath table ahead of time 2020-03-05 17:23:44 -08:00
Hamish Knight
c26eb11baf Merge pull request #30190 from hamishknight/the-beginning-of-the-pipeline-end
Requestify SourceFile parsing
2020-03-05 11:17:24 -08:00
Alexis Laferrière
7bd585001a [AST] Intro and use isSPI and getSPIGroups 2020-03-04 16:42:18 -08:00