Commit Graph

205 Commits

Author SHA1 Message Date
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
swift_jenkins
f5510bf1a4 Merge remote-tracking branch 'origin/master' into master-next 2020-04-20 16:57:12 -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
5b22910830 Remove Fallback Infrastructure For Evaluator-Based Dependencies 2020-04-20 10:36:29 -07:00
Robert Widmann
94166024fa Dump all uses of the legacy referenced name tracker 2020-04-20 10:22:58 -07:00
Michael Forster
36279e2b6e Use LLVM version of combineHashValue
This fixes the master-next build.
2020-04-20 11:46:27 +02:00
Nate Chandler
81dc64fee3 @main: Enable main function to throw.
SE-0281 was accepted with the modification that the main function should
be allowed to be throwing.  Here support for enabling that is added.

Support is implemented in two steps:

(1) The $main wrapper function is modified to be throwing

static func $main() throws {
  return try main()
}

whenever the main function is throwing (it remains non-throwing when
$main is not throwing).

(2) The @main entry point is modified to be

sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
entry(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
  %the_main_type = metatype $@thin TheMainType.Type
  %the_main_func = function_ref @`TheMainType.main()` : $@convention(method) (@thin TheMainType.Type) -> @error Error
  try_apply %the_main_func(%the_main_type) : $@convention(method) (@thin TheMainType.Type) -> @error Error, normal success, error failure

success(%_ : $()):
  %success_code_builtin_int32 = integer_literal $Builtin.Int32, 0
  br bb1(%success_code_builtin_int32 : $Builtin.Int32)

failure(%error : @owned $Error):
  %_ = builtin "errorInMain"(%error : $Error) : $()
  end_lifetime %error : $Error
  %error_code_builtin_int32 = integer_literal $Builtin.Int32, 1
  br bb1(%error_code_builtin_int32 : $Builtin.Int32)

exit(%code_builtin_int32 : $Builtin.Int32):
  %code = struct $Int32 (%code_builtin_int32 : $Builtin.Int32)
  return %code : $Int32
}

whenever the main function is throwing (and consequently $main also is).

In the non-throwing case, (a) the try_apply instruction is replaced with an
apply instruction, (b) the body of the success block is appended to the
entry block, and (c) the success and failure blocks are removed.
2020-04-17 11:33:31 -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
Dan Zheng
20dedfb40f [Gardening] Remove unnecessary forward declaration. 2020-04-09 01:10:47 -07: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
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
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
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
3f8f3a89cb Teach the Evaluator about Incremental Dependencies
Formalize DependencyScope, DependencySource, and the incremental dependency stack.

Also specialize SimpleRequest to formalize dependency sources and dependency sinks. This allows the evaluator's internal entrypoints to specalize away the incremental dependency tracking infrastructure if a request is not actually dependency-relevant.
2020-03-31 15:40:04 -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
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
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
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
Robert Widmann
52c808648f Move the defined functions list onto SourceFile 2020-03-16 19:19:01 -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
8e5ca8abdf [NFC] Generate #file -> #filePath table ahead of time 2020-03-05 17:23:44 -08:00
Hamish Knight
df34be72e8 [AST] Remove parsing ASTStages
Now that the parsing stage has been
requestified, these are no longer
meaningful.
2020-03-03 15:53:18 -08:00
Hamish Knight
011f4f1584 Requestify SourceFile parsing
Add ParseSourceFileRequest that parses a SourceFile
for its top-level decls.
2020-03-03 15:53:18 -08:00
Hamish Knight
2724cf6f65 [Parse] Check the SourceFile to see if bodies can be delayed
Remove the `DelayBodyParsing` flag from the parser
and instead query the source file.
2020-03-02 14:12:37 -08:00
Hamish Knight
2ec619caf7 [AST] Add a few parsing flags to SourceFile
Add flags for whether delayed body parsing or #if
condition evaluation is disabled, as well as
whether warnings should be suppressed. Then pass
down these flags from the frontend.

This is in preparation for the requestification of
source file parsing where the SourceFile will need
to be able to parse itself on demand.
2020-03-02 14:12:37 -08:00
Hamish Knight
d77cae6720 Move PersistentParserState onto SourceFile
Move the global PersistentParserState from
the CompilerInstance to the source file that code
completion is operating on, only hooking up the
state when it's needed. This will help make it
easier to requestify source file parsing.
2020-03-02 11:22:44 -08:00
Alexis Laferrière
0e7029dfb5 Use "SPI group" for the name used in an @_spi attribute 2020-02-19 14:18:11 -08:00
Alexis Laferrière
2e73cb44fd [Sema] Type-check the use and exposability of SPI decls 2020-02-19 14:17:14 -08:00
Alexis Laferrière
501f458879 [AST] Intro service lookupImportedSPIs to find direct SPI imports of a module 2020-02-19 14:17:14 -08:00
Alexis Laferrière
d5969a9f3a [AST] Intro SPI attribute for access control and imports 2020-02-19 14:17:08 -08:00
Brent Royal-Gordon
d6bccba9b6 Load cross-import overlays 2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
03832cbc9b [NFC] Allow ImportedModuleDesc to be a DenseMap key 2020-02-18 11:07:12 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
Slava Pestov
0555de5469 Sema: Remove a couple of calls to clearLookupCache()
Tests seem to pass without these.

Two calls still remain, in ModuleDecl::addFiles() and removeFiles().
It will take a bit more refactoring to eliminate those.
2020-02-17 21:49:02 -05:00
David Ungar
d61f6f2f66 Changes to support per-type-body fingerprints. 2020-01-27 15:14:46 -08:00
Robert Widmann
6784575de1 Introduce a special LLDB-only way to prepend decls
SwiftASTManipulator is installing declarations in the wrong order, and
currently fails a REPL test if the right API is used.

rdar://58355191 is tracking the removal of this entrypoint.
2020-01-06 14:51:10 -08:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
Saleem Abdulrasool
7d8aac60ca disambiguate some type shadowing (NFCI)
Adjust the type shadowing identified by GCC 7.  The declaration shadows
a type which changes the meaning of the identifier subsequently.
2019-12-23 15:34:55 -08:00
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00
Robert Widmann
371526bdea Add a high-level request to type check a file 2019-12-03 17:16:14 -08:00
Slava Pestov
2cada3bce1 Revert "Eagerly TypeCheck Synthesized Decls"
This reverts commit cab4e9f011.
2019-11-22 17:41:34 -05:00
Robert Widmann
cab4e9f011 Eagerly TypeCheck Synthesized Decls 2019-11-11 11:34:52 -08:00