Commit Graph

667 Commits

Author SHA1 Message Date
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00
Brent Royal-Gordon
d55c5bd549 [NFC] Add type for ModuleDecl::getImplicitImports()
This doesn’t really change the design yet.
2020-10-09 18:58:03 -07:00
Brent Royal-Gordon
c489fffb79 [NFC] Rename and document fields of AttributedImport
Also renames a member in ImportResolution.cpp to align with this naming.
2020-10-09 18:57:07 -07:00
Brent Royal-Gordon
f3d99cefbb [NFC] Turn ImportedModuleDesc into AttributedImport
Rename ImportedModuleDesc to AttributedImport and make it a template that’s parameterized on the representation of the module. This will allow us to reduce duplicated representations of “abstract” ImportDecls.
2020-10-09 18:57:07 -07:00
Brent Royal-Gordon
b440ab7331 [NFC] Move several types/functions to Import.h
To help consolidate our various types describing imports, this commit moves the following types and methods to Import.h:

* ImplicitImports
* ImplicitStdlibKind
* ImplicitImportInfo
* ModuleDecl::ImportedModule
* ModuleDecl::OrderImportedModules (as ImportedModule::Order)
* ModuleDecl::removeDuplicateImports() (as ImportedModule::removeDuplicates())
* SourceFile::ImportFlags
* SourceFile::ImportOptions
* SourceFile::ImportedModuleDesc

This commit is large and intentionally kept mechanical—nothing interesting to see here.
2020-10-09 18:57:07 -07:00
Robert Widmann
f1f5961e0f [NFC] Add Incremental Info Bits to ModuleDecl 2020-09-24 20:07:01 -06:00
Varun Gandhi
4b5d885114 [NFC] Clarify semantics of getImportedModules.
The lack of clarity manifested as unexpected behavior when using
getImportedModules to create the module import graph. The new behavior
makes SPI-ness and Shadowing-ness behave similarly in terms of
filtering. We also check if a filter is well-formed to avoid
accidental empty import lists.
2020-09-23 12:50:37 -07:00
Varun Gandhi
d3369f7711 [NFC] Rename ImportFilterKind cases to be clearer. 2020-09-23 12:50:20 -07:00
Brent Royal-Gordon
6f2853695b [NFC] Delete obsolete AccessPathTy-based code
This was all deprecated in earlier commits.
2020-09-10 19:08:29 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Alexis Laferrière
cbb7228451 [Sema] Evaluate SPI groups for all decls, not only public ones
Remove the fast path skipping evaluating SPI groups for non-public
decls. This knowledge is still required to allow the use of SPI types in
the signatures of `@usableFromInline` declarations and in internal
properties of structs in non library evolution compilation.

rdar://68530659
rdar://68527580
2020-09-08 16:58:45 -07:00
Slava Pestov
193cf0de87 Code review feedback from @davidungar 2020-09-04 19:59:17 -04:00
Slava Pestov
4923aab2ea AST: Add hoisted declarations to unqualified name lookup cache 2020-09-03 16:16:50 -04:00
Slava Pestov
fae8f944b8 AST: Add 'hoisted' flag to Decl 2020-09-03 16:16:50 -04:00
Alexis Laferrière
fd78da5137 [ModuleInterface] Don't print extensions to implementation-only imported types
Extensions to implementation-only types are accepted at type-checking
only if they don't define any public members. However if they declared a
conformance to a public type they were also printed in the
swiftinterface, making it unparsable because of an unknown type.

Still accept such extensions but don't print them.

rdar://problem/67516588
2020-08-20 17:12:31 -07:00
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04:00
Rintaro Ishizaki
513fed7d8c [CodeCompletion] Enable ASTScope in code completion
* Re-create `ASTScope` for each completion
* Add generic params and where clause scope even without missing body
* Use `getOriginalBodySourceRange()` for `AbstractFunctionBodyScope`
* Source range translations for replaced ranges when finding scopes
* Bypass source range checks when the completion happens in the replaced
  range
* Be lenient with ASTScope / DeclContext mismatch in code completion
2020-08-12 16:36:09 -07:00
Matei Oprea
6ae04f749b [NFC] Remove ModuleDecl::isClangModule in favor of isNonSwiftModule. (#33202)
Fixes SR-13237.
2020-08-03 20:01:17 -07:00
Nikhil
96587bc2d4 Refactor construction of ModuleDecl::ImportFilters to use new initializer list constructor (#33250)
This commit makes code cleaner by using newly introduced
 initializer list construction
2020-08-01 14:24:44 -07:00
Brent Royal-Gordon
4394e92c3f Merge pull request #32700 from brentdax/magical-and-evolutionary
Revise #file changes from SE-0274
2020-07-17 01:57:23 -07:00
Alexis Laferrière
47e4e29362 [Sema] SPI info on a wrapped property should propagate to the backing storage 2020-07-16 14:47:28 -07:00
Brent Royal-Gordon
0e569f5d9e Add support for #fileID
This temporarily breaks -enable-experimental-concise-pound-file.

fixup adding #fileID
2020-07-13 14:05:13 -07:00
Brent Royal-Gordon
d4ebd5df06 [NFC] Avoid violating same-filename rule in tests
…and modify resolveFileIDConflicts() to diagnose any such violations instead of asserting.

Swift does not allow any two files in the same module to have the same filename, even if they are in different directories. However, this is enforced in the driver, so tests that invoke the frontend directly can violate it. Turns out that a couple of those snuck into the test suite at various points.

This commit updates those tests. It also causes the frontend to diagnose the duplicate filename error just as the driver would have, which should help us understand what happened more easily if this crops up again in the future.

NFC, since invoking the frontend directly is unsupported.
2020-07-13 14:05:13 -07:00
Brent Royal-Gordon
7f91145efc [NFC] Rename “MagicFileString” -> “FileID”
Doing this NFC renaming first helps clarify the functional changes to come.
2020-07-13 14:05:13 -07:00
Xi Ge
b65300f34e Merge pull request #32245 from nkcsgexi/scan-overlay-file
DependenciesScanner: teach the scanner to handle cross-import overlays
2020-06-09 13:39:38 -07:00
Xi Ge
42cc989136 DependenciesScanner: teach the scanner to handle cross-import overlays 2020-06-09 10:38:52 -07:00
Hamish Knight
5d72c464eb [Frontend] Remove parsing option params from performParseOnly
Lift the `DisablePoundIfEvaluation` parsing option
into `LangOptions` to subsume the need for the
`EvaluateConditionals` parameter, and sink the
computation of `CanDelayBodies` down into
`createSourceFileForMainModule`.
2020-06-08 12:44:13 -07:00
Hamish Knight
db9a27e24a [AST] Remove hasSyntaxRoot
Use `shouldBuildSyntaxTree` instead.
2020-06-07 20:26:31 -07:00
Hamish Knight
f57299a587 Formalize some SourceFile parsing outputs
Currently when parsing a SourceFile, the parser
gets handed pointers so that it can write the
interface hash and collected tokens directly into
the file. It can also call `setSyntaxRoot` at
the end of parsing to set the syntax tree.

In preparation for the removal of
`performParseOnly`, this commit formalizes these
values as outputs of `ParseSourceFileRequest`,
ensuring that the file gets parsed when the
interface hash, collected tokens, or syntax tree
is queried.
2020-06-03 11:03:56 -07:00
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