Commit Graph

429 Commits

Author SHA1 Message Date
Doug Gregor
2a28fed34d Allow one to separately specify the ABI name of a module.
Introduce a new compiler flag `-module-abi-name <name>` that uses the
given name as the ABI name for the module (rather than the module's
name in source code). The ABI name impacts name mangling and metadata.
2021-03-12 07:42:07 -08:00
Becca Royal-Gordon
01fa74510e [NFC] Clean up access note code
• Rename properties for greater consistency with the YAML file
• Rename AccessNotes -> AccessNotesFile
• Add doc comments
• Miscellaneous comment/style improvements.
2021-02-09 14:17:35 -08:00
Becca Royal-Gordon
ccf244b89b Add ability to load access notes 2021-02-09 14:17:33 -08:00
Robert Widmann
b960c6e31c Derive a Fingerprint from a Module's BasicSourceFileInfo 2021-02-02 09:57:46 -08:00
Erik Eckstein
e3d636e519 CrossModuleOptimization: fix crash when importing a module as implementationOnly
If a function uses a type imported as implementationOnly (or similar), it cannot be serialized.

I added a new API in ModuleDecl (canBeUsedForCrossModuleOptimization), which performs this check.

rdar://72864719
2021-01-18 13:09:27 +01:00
Rintaro Ishizaki
36cfd10041 Cosmetic changes 2021-01-13 13:29:57 -08:00
Rintaro Ishizaki
a9a044c6e3 [Serialization] Serialize fingerprint, mtime, size of the source files 2021-01-13 11:49:52 -08:00
Rintaro Ishizaki
1b6e7857c2 [Serialization] Serialize/deserialize source file list 2021-01-13 11:49:52 -08:00
Arnold Schwaighofer
2b6ba2830c Serialize decls with _specialize(exported:true, target: somefunc(_:), ...) in a list for fast lookup
rdar://71430641
2020-12-11 09:58:32 -08:00
Robert Widmann
883902411b Migrate loadFingerprint onto ModuleDecl and Friends 2020-11-18 12:20:14 -08:00
Artem Chikin
0305f20f32 [Clang Importer] Do not rely on being able to always import Foundation on-demand
When importing Clang types.
This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on `Foundation`, then attempting to load it will produce an error because Implicit module loading is no longer allowed..

This change addresses a small number of cases where ClangImporter relies on being able to load `Foundation` on-demand:
- When importing a single Decl from a clang module, we check whether it has certain conformances by checking all extensions of the NominalTypeDecl of the Decl in question, to see if any of the extensions contain the conformance we are looking for, but we only check extensions whose parent module is either the original module of the NominalTypeDecl or the overlay module of the NominalTypeDecl or Foundation. It seems that we do not need to actually import `Foundation` here, just checking the module Identifier should be sufficient.
- In `maybeImportNSErrorOutParameter`, change the behavior to have an exit condition based on whether `Foundation` can be imported, before attempting to load it.
- When checking whether or not we are allowed to bridge an Objective-C type, it also looks sufficient the query whether or not `Foundation` *can* be imported, without loading it.
2020-10-28 14:47:17 -07:00
Varun Gandhi
1f479896f4 Revert "[NFC] Clarify semantics of getImportedModules."
This reverts commit 4b5d885114.
2020-10-23 10:01:35 -07:00
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
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
Robert Widmann
513d108a0e [NFC] Drop SourceFileKind from getMainSourceFile
The parameter here was derived from the CompilerInvocation-level parsing bits, which doesn't make any sense. This state is going away soon, so drop the parameter.
2020-09-11 21:11:58 -06: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
Brent Royal-Gordon
5afe2f97e2 [NFC] Move ImportKind to a new Import.h header 2020-09-10 18:36:03 -07:00
Saleem Abdulrasool
7128611a9d AST: align ImportedModule to 64-bits
Align `ImportedModule` to 64-bits as it is used in other types which
force the 8-byte alignment for the layout.
2020-09-06 11:14:46 -07: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
Matei Oprea
6ae04f749b [NFC] Remove ModuleDecl::isClangModule in favor of isNonSwiftModule. (#33202)
Fixes SR-13237.
2020-08-03 20:01:17 -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
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
42cc989136 DependenciesScanner: teach the scanner to handle cross-import overlays 2020-06-09 10:38:52 -07: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
Varun Gandhi
2419112469 Merge pull request #32080 from varungandhi-apple/vg-tidying-up-without-marie-kondo
Get rid of #includes that do not spark joy
2020-06-01 19:51:01 -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
Varun Gandhi
f85492161c [NFC] Remove redundant includes for llvm/ADT/SetVector.h. 2020-05-31 13:07:45 -07:00
Varun Gandhi
fea589e470 [NFC] Remove redundant includes for llvm/ADT/DenseSet.h. 2020-05-31 13:07:45 -07:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Varun Gandhi
ba4b43a96b [NFC] Remove redundant includes for llvm/ADT/TinyPtrVector.h. 2020-05-31 13:07:41 -07:00
Hamish Knight
046f17f519 [AST] Move the empty module assertion
Start asserting in `ModuleDecl::getFiles`
that the module is either non-empty or has
failed to load. This ensures that module
loading doesn't attempt to query the module's
files until the ModuleFile has been installed.
2020-05-28 12:09:11 -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
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
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
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
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
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
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
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
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