Commit Graph

1894 Commits

Author SHA1 Message Date
Holly Borla
2d893d23bf [GenericEnvironment] For opened pack element environments, only include element type
parameters whose originating packs are in a given shape equivalence class.
2023-01-08 12:59:08 -08:00
Holly Borla
715de13dbf [Sema] Key opened pack element generic on the shape class of the expansion. 2023-01-07 15:07:51 -08:00
Artem Chikin
12477b7b79 [Dependency Scanning] Refactor the scanner to resolve unqualified module imports
This changes the scanner's behavior to "resolve" a discovered module's dependencies to a set of Module IDs: module name + module kind (swift textual, swift binary, clang, etc.).

The 'ModuleDependencyInfo' objects that are stored in the dependency scanner's cache now carry a set of kind-qualified ModuleIDs for their dependencies, in addition to unqualified imported module names of their dependencies.

Previously, the scanner's internal state would cache a module dependnecy as having its own set of dependencies which were stored as names of imported modules. This led to a design where any time we needed to process the dependency downstream from its discovery (e.g. cycle detection, graph construction), we had to query the ASTContext to resolve this dependency's imports, which shouldn't be necessary. Now, upon discovery, we "resolve" a discovered dependency by executing a lookup for each of its imported module names (this operation happens regardless of this patch) and store a fully-resolved set of dependencies in the dependency module info.

Moreover, looking up a given module dependency by name (via `ASTContext`'s `getModuleDependencies`) would result in iterating over the scanner's module "loaders" and querying each for the module name. The corresponding modules would then check the scanner's cache for a respective discovered module, and if no such module is found the "loader" would search the filesystem.

This meant that in practice, we searched the filesystem on many occasions where we actually had cached the required dependency, as follows:
Suppose we had previously discovered a Clang module "foo" and cached its dependency info.
-> ASTContext.getModuleDependencies("foo")
--> (1) Swift Module "Loader" checks caches for a Swift module "foo" and doesn't find one, so it searches the filesystem for "foo" and fails to find one.
--> (2) Clang Module "Loader" checks caches for a Clang module "foo", finds one and returns it to the client.

This means that we were always searching the filesystem in (1) even if we knew that to be futile.
With this change, queries to `ASTContext`'s `getModuleDependencies` will always check all the caches first, and only delegate to the scanner "loaders" if no cached dependency is found. The loaders are then no longer in the business of checking the cached contents.

To handle cases in the scanner where we must only lookup either a Swift-only module or a Clang-only module, this patch splits 'getModuleDependencies' into an alrady-existing 'getSwiftModuleDependencies' and a newly-added 'getClangModuleDependencies'.
2023-01-05 11:44:06 -08:00
Artem Chikin
1230966e80 [Dependency Scanner] Rename 'ModuleDependenceis' -> 'ModuleDependencyInfo' 2022-12-15 14:18:29 -08:00
John McCall
2d5985b9cc Track whether a type contains an element archetype in the recursive properties.
Being able to efficiently query for a local archetype is important in SIL.
2022-12-14 19:43:23 -05:00
Artem Chikin
f39c6385df [Dependency Scanning] Do not disambiguate 'GlobalModuleDependenciesCache' by search path set
This is no longer necessary since the cache is always configured for the current scanning context hash, which includes the search path set.
2022-12-06 14:15:39 -08:00
Doug Gregor
1b8b706dac Merge pull request #62405 from DougGregor/macro-diagnostics 2022-12-05 21:37:27 -08:00
Doug Gregor
f0fc1c51bb Remove compiler plugin support library
The functionality of the compiler plugin support library has been
subsumed into parts of the compiler. Remove the functionality and its
last test.
2022-12-05 12:54:36 -08:00
Slava Pestov
2ebddf5817 Merge pull request #62180 from slavapestov/printing-variadic-types
Fixes for printing variadic generic types
2022-12-02 16:01:13 -05:00
Slava Pestov
77a67e1da0 AST: Relax assertions in PackType::get() 2022-12-02 11:15:43 -05:00
Egor Zhdan
9f542898cd Merge pull request #62293 from apple/egorzhdan/synthesize-cxx-convertible
[cxx-interop] Synthesize conformances to `CxxConvertibleToCollection`
2022-12-01 11:44:02 +00:00
Doug Gregor
e1102cc098 Merge pull request #62204 from DougGregor/macro-declarations
Macro declarations
2022-11-29 10:04:09 -08:00
Egor Zhdan
cb562d26b8 [cxx-interop] Synthesize conformances to CxxConvertibleToCollection
This extends the existing auto-conformance mechanism to synthesize the conformances to `CxxConvertibleToCollection` protocol for C++ sequence types.

This means that the developer can now call `Array(myCxxSequence)` or `Set(myCxxSequence)` without adding any extensions manually.
2022-11-29 14:28:17 +00:00
Slava Pestov
34ce74aea8 AST: Stricter invariants when constructing TypeAliasType 2022-11-28 23:57:53 -05:00
Doug Gregor
813dc12ad3 [Macros] Use the external module/type name in lieu of macro registration.
A macro declaration contains the external module and type name of the
macro's implementation. Use that information to find the macro type
(via its type metadata accessor) in a loaded plugin, so we no longer
require the "allMacros" array. Instead, each macro implementation type
must be a public struct.

Since we are now fully dependent on the macro declaration for
everything about a macro except its kind, remove most of the query
infrastructure for compiler plugins.

Replace the macro registration scheme based on the allMacros array with
2022-11-28 18:32:43 -08:00
Alexis Laferrière
c266e9dce5 Merge pull request #62185 from xymus/improve-rmodule-loading
Improve `-Rmodule-loading` to show both the path to the source and to the cached file actually loaded
2022-11-28 14:25:15 -08:00
Holly Borla
c225fc428b Merge pull request #62228 from hborla/pack-element-generic-environment
[GenericEnvironment] Include original parameter packs in opened pack element signatures.
2022-11-28 15:34:35 -05:00
Holly Borla
8ec5405a30 [GenericEnvironment] Store a substitution map for the outer generic parameters
of an opened pack element generic environment.
2022-11-23 11:17:05 -05:00
Holly Borla
6d65c11b4a [GenericEnvironment] Model opened pack element signatures as a complete clone
of the outer context signature, with an additional set of element type parameters
at depth + 1.
2022-11-23 11:16:27 -05:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alexis Laferrière
319d49816d [Frontend] -Rmodule-loading shows both source path and cached path 2022-11-18 15:28:16 -08:00
Alexis Laferrière
d313760792 [Frontend] Report Swift overlays loaded for indirect cland dependencies 2022-11-18 10:44:07 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Doug Gregor
19d1588d13 [Macros] Handle macro overloading.
Allow more than one macro plugin to introduce a macro with the same
name, and let the constraint solver figure out which one to call. Also
eliminates a potential use-after-free if we somehow find additional
compiler plugins to load after having expanded a macro.
2022-11-13 16:29:48 -08:00
Slava Pestov
16a84fc382 AST: Rename ProtocolDecl::getExistentialType() to getDeclaredExistentialType() 2022-11-07 18:38:06 -05:00
Egor Zhdan
1a1afeb410 Merge pull request #61909 from apple/egorzhdan/cxx-synthesize-rac
[cxx-interop] Synthesize conformances to `CxxRandomAccessCollection`
2022-11-04 11:48:02 -07:00
Robert Widmann
7944635f2e Merge pull request #61898 from CodaFi/i-write-syns-not-tragedies 2022-11-04 08:20:47 -07:00
Egor Zhdan
3cf84214b8 [cxx-interop] Synthesize conformances to CxxRandomAccessCollection
This makes ClangImporter automatically conform C++ collection types to `Cxx.CxxRandomAccessCollection` protocol.

We consider a C++ sequence type to be a random access collection type its iterator conforms to `UnsafeCxxRandomAccessIterator`.
2022-11-03 12:01:18 -07:00
Richard Wei
d059735260 [Macros] Type check user-defined macro plugins (#61861)
Type check user-defined macros plugins with user-provided type signatures.

Also, load plugin libraries with `RTLD_LOCAL` instead of `RTLD_GLOBAL` to prevent symbol collision between plugins. `llvm::sys::DynamicLibrary` only supports `RTLD_GLOBAL` so we use the plain `dlopen` instead. This does not work on Windows and needs to be fixed.

Friend PR: apple/swift-syntax#1042
2022-11-02 18:22:31 -07:00
Robert Widmann
2d07f382c5 Delete _InternalSwiftSyntaxParser And Its Build Infrastructure
This is the start of the removal of the C++ implementation of libSyntax
in favor of the new Swift Parser and Swift Syntax libraries. Now that
the Swift Parser has switched the SwiftSyntaxParser library over to
being a thin wrapper around the Swift Parser, there is no longer any
reason we need to retain any libSyntax infrastructure in the swift
compiler.

As a first step, delete the infrastructure that builds
lib_InternalSwiftSyntaxParser and convert any scripts that mention
it to instead mention the static mirror libraries. The --swiftsyntax
build-script flag has been retained and will now just execute the
SwiftSyntax and Swift Parser builds with the just-built tools.
2022-11-02 10:35:29 -07:00
Alexis Laferrière
47b29b68db Merge pull request #61649 from xymus/index-swiftinterfaces
[Index] Force indexing of system modules to read only from swiftinterfaces
2022-10-31 14:18:45 -07:00
Richard Wei
4ce1ebb120 [Macros] Support user-defined macros as compiler plugins (#61734)
Allow user-defined macros to be loaded from dynamic libraries and evaluated.

- Introduce a _CompilerPluginSupport module installed into the toolchain. Its `_CompilerPlugin` protocol acts as a stable interface between the compiler and user-defined macros.
- Introduce a `-load-plugin-library <path>` attribute which allows users to specify dynamic libraries to be loaded into the compiler.

A macro library must declare a public top-level computed property `public var allMacros: [Any.Type]` and be compiled to a dynamic library. The compiler will call the getter of this property to obtain and register all macros.

Known issues:
- We current do not have a way to strip out unnecessary symbols from the plugin dylib, i.e. produce a plugin library that does not contain SwiftSyntax symbols that will collide with the compiler itself.
- `MacroExpansionExpr`'s type is hard-coded as `(Int, String)`. It should instead be specified by the macro via protocol requirements such as `signature` and `genericSignature`. We need more protocol requirements in `_CompilerPlugin` to handle this.
- `dlopen` is not secure and is only for prototyping use here.

Friend PR: apple/swift-syntax#1022
2022-10-31 14:03:25 -07:00
Alexis Laferrière
730497e9a3 [Serialization] Add control over adding a loaded module to the in-memory cache 2022-10-31 10:58:57 -07:00
Alexis Laferrière
5ed1f1236d [Sema|Index] Ignore the cache when loading a system module for indexing 2022-10-31 10:58:57 -07:00
Alexis Laferrière
83cd432785 [Frontend] Intro global control to force loading from swiftinterface
Intro ASTContext::setIgnoreAdjacentModules to change module loading to
accept load only resilient modules from their swiftinterfaces, ignoring
the adjacent module and any silencing swiftinterfaces errors.
2022-10-31 10:58:54 -07:00
Holly Borla
e2a41d126a Merge pull request #61737 from hborla/generic-environment-helpers
[GenericEnvironment] Add helper methods for mapping pack types to opened element types and vice versa.
2022-10-26 16:16:12 -07:00
Egor Zhdan
ea781bf657 Merge pull request #61700 from apple/egorzhdan/cxx-conform-raciter
[cxx-interop] Synthesize conformances to `UnsafeCxxInputIterator`
2022-10-26 18:34:32 +01:00
Holly Borla
1ab9f8f7c6 [AST] Add helper methods to GenericTypeParamType for converting a given type
parameter to and from a pack type parameter.
2022-10-26 00:04:56 -07:00
Holly Borla
5c9b8bf5b6 [GenericSignature] Correct the order of arguments to GenericTypeParamType::get
when creating the generic signature for an opened pack element.
2022-10-24 16:15:40 -07:00
Egor Zhdan
0efd20d016 [cxx-interop] Synthesize conformances to UnsafeCxxInputIterator
This makes ClangImporter automatically conform C++ sequence types to `Cxx.UnsafeCxxInputIterator` protocol.

We consider a C++ type to be a random access iterator type if conforms to `UnsafeCxxInputIterator`, and additionally defines `operator-` and `operator+=`.
2022-10-24 17:18:42 +01:00
Holly Borla
ad962d8ed1 [AST] Allow tuple types with consecutive pack expansions. 2022-10-23 22:45:47 -07:00
Slava Pestov
90952fbdd5 AST: Push memoization down from OpaqueTypeArchetypeType::get() to GenericEnvironment::forOpaqueType() 2022-10-21 21:55:35 -04:00
Slava Pestov
68514b10b5 AST: Introduce ElementArchetypeType 2022-10-21 21:55:35 -04:00
Slava Pestov
fec6c06240 AST: TupleType::get() asserts if pack expansion type is followed by an unlabeled element 2022-10-16 21:37:24 -04:00
Slava Pestov
d9cf85d72a AST: Relax an invariant in PackExpansionType::get()
The expression type checker replaces type variables with UnresolvedType
and PlaceholderType sometimes, so allow them to appear here.
2022-10-16 21:37:24 -04:00
Hamish Knight
6aa44a1754 [AST] Remove @_typeSequence attribute
This is no longer needed now that we have the
ellipsis spelling.
2022-10-14 15:40:13 +01:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00