Commit Graph

588 Commits

Author SHA1 Message Date
Hamish Knight
60eae88fd1 Sink some parsing options into SourceFile::ParsingFlags
Sink the `BuildSyntaxTree` and
`CollectParsedTokens` bits into
`SourceFile::ParsingFlags`, with a static method
to get the parsing options from the lang opts.

Also add a parsing flag for enabling the interface
hash, which can be used instead of calling
`enableInterfaceHash`.
2020-06-03 11:03:55 -07:00
Hamish Knight
b5ab29b70c NFC: Inline canBeParsedInFull
Now that SIL files no longer interleave parsing
with type-checking, the query doesn't make much
sense. Inline it into its only client,
`shouldBuildSyntaxTree`.
2020-06-03 11:03:55 -07:00
Hamish Knight
b857b224c7 NFC: Rename shouldCollectToken -> shouldCollectTokens
And fix the name of the underlying vector.
2020-06-03 11:03:54 -07:00
Hamish Knight
d26f4148a9 [CodeCompletion] Replace main module instead of file
Rather than replacing the code completion file
on the `CompilerInstance` whenever we do a cached
top-level completion, let's set a new main module
instead.

This allows us to properly update the
`LoadedModules` map, and allows the retrieval of
the code completion file to be turned into a
request.
2020-06-02 14:25:28 -07:00
Hamish Knight
e1eb27a4dd Merge pull request #32139 from hamishknight/prime-time 2020-06-02 13:38:23 -07:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Hamish Knight
e60c7fe547 Add request to query primary files
Remove the `PrimarySourceFiles` vector from the
frontend and replace it with a request on
ModuleDecl that retrieves the primary files for
the main module.

This is in preparation for having
`CompilerInstance::getMainModule` automatically
populate the main module with files when queried.
2020-06-02 09:10:35 -07:00
Alexis Laferrière
21bf781067 Merge pull request #32049 from xymus/spi-unique-imports
[ModuleInterface] Print the SPI attribute only once per group and import
2020-06-01 11:24:21 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Hamish Knight
439c1481be Assert that an added file loaded without error 2020-05-28 15:19:19 -07:00
Hamish Knight
6477cc68eb [Serialization] Delay adding ModuleFiles until they're loaded
Rather than adding a ModuleFile to a parent module
and then removing it afterwards if it fails to
load, let's wait until we've loaded the file before
deciding to add it to the parent module. This then
allows us to get rid of `ModuleDecl::removeFile`.

In addition, push down the calls to `addFile` into
the callers of `loadAST` in preparation for
`addFile` being replaced with a one-time-only call
to a `setFiles` method.
2020-05-28 12:09:10 -07:00
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
Hamish Knight
1de3d0dbef Merge pull request #31943 from owenv/line-and-col 2020-05-25 17:57:09 -07:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
Robert Widmann
acbf927b0e [NFC] Delete ReferencedNameTracker 2020-05-21 18:54:14 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Hamish Knight
cc062ee2bb Fix precedencegroup and operator decl lookup
Re-implement operator and precedencegroup decl
lookup to use `namelookup::getAllImports` and
existing decl shadowing logic. This allows us to
find operator decls through `@_exported` imports,
prefer operator decls defined in the same module
over imported decls, and fixes a couple of other
subtle issues.

Because this new implementation is technically
source breaking, as we can find multiple results
where we used to only find one result, it's placed
behind the new Frontend flag
`-enable-new-operator-lookup` (with the aim of
enabling it by default when we get a new language
mode).

However the new logic will always be used if the
result is unambiguous. This means that e.g
`@_exported` operators will be instantly available
as long as there's only one candidate. If multiple
candidates are found, we fall back to the old
logic.

Resolves SR-12132.
Resolves rdar://59198796.
2020-05-18 14:33:43 -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