Commit Graph

1674 Commits

Author SHA1 Message Date
Egor Zhdan
8d7d0efe13 [cxx-interop] Add UnsafeCxxMutableInputIterator protocol
This is an inheritor of the existing `UnsafeCxxInputIterator` protocol, with the only difference being the ability to mutate `var pointee` via a non-const `operator*()`.

This is needed to support mutable subscripts for `std::map` via `CxxDictionary`.

rdar://105399019
2023-07-26 18:20:49 +01:00
Slava Pestov
3064a00a2a AST: Use transformTypeParameterPacks() in getOpenedElementSignature() 2023-07-12 18:02:14 -04:00
Slava Pestov
8afff61699 AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
This basically undoes 3da6fe9c0d, which in hindsight was wrong.

There were no other usages of TypeArrayView anywhere else except for
GenericSignature::getGenericParams(), and it was almost never what
you want, so callers had to convert back and forth to an ArrayRef.
Remove it.
2023-06-29 19:23:44 -04:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Egor Zhdan
b79b65c056 [cxx-interop] Allow inserting elements into std::set from Swift
`std::set::insert` isn't exposed into Swift, because it returns an instance of an unsafe type.

This change adds a Swift overload of `insert` for `std::set` and `std::unordered_set` that has the return type identical to `Swift.Set.insert`: a tuple of `(inserted: Bool, memberAfterInsert: Element)`.

rdar://111036912
2023-06-20 16:56:54 +01:00
Konrad `ktoso` Malawski
b420190059 Merge pull request #66695 from ktoso/wip-distributed-harden-empty-impls
[Distributed] Harden typechecker against completely empty DAS types
2023-06-16 22:24:43 +09:00
Konrad `ktoso` Malawski
fc7ecc8f67 [Distributed] Harden typechecker against completely empty DAS types 2023-06-16 11:54:51 +09:00
Rintaro Ishizaki
5791a2cb37 [Macros] Plugin search options group
'load-plugin-library', 'load-plugin-executable', '-plugin-path' and
'-external-plugin-path' should be searched in the order they are
specified in the arguments.

Previously, for example '-plugin-path' used to precede
'-external-plugin-path' regardless of the position in the arguments.
2023-06-14 15:46:39 -07:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Nate Chandler
bd03dbad3f [AST] Added hasConcretePack recursive property. 2023-06-05 08:11:28 -07:00
Doug Gregor
7386a7e7bd [Macros] Rework the way we assign closure and local discriminators
Setting closure and local discriminators depends on an in-order walk
of the AST. For macros, it was walking into both macro expansions and
arguments. However, this doesn't work well with lazy macro expansions,
and could result in some closures/local variables not getting
discriminators set at all.

Make the assignment of discriminators only walk macro arguments, and
then lazily assign discriminators for anything within a macro
expansion or in ill-formed code. This replaces the single global "next
autoclosure discriminator" scheme with a per-DeclContext scheme, that
is more reliable/robust, although it does mean that discriminators
of closures and locals within macro expansions are dependent on
ordering. That shouldn't matter, because these are local values.

Fixes rdar://108682196.
2023-05-28 16:49:20 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Rintaro Ishizaki
3637885139 [Macros] Rearrange plugin search order
New ordring is:
1) `-load-plugin-library`
2) `-load-plugin-executable`
3) `-plugin-path`
4) `-external-plugin-path`

rdar://109163929
2023-05-17 10:53:36 -07:00
Hamish Knight
c0e013907e [AST] Allocate PlaceholderTypes in the correct arena
We shouldn't be allocating placeholders for type
variables in the permanent arena, and we should be
caching them such that equality works.

To achieve this, we need to introduce a new
"solver allocated" type property. This is required
because we don't want to mark placeholder types
with type variable originators as themselves having
type variables, as it's not part of their structural
type. Also update ErrorType to use this bit, though
I don't believe we currently create ErrorTypes
with type variable originators.
2023-05-06 20:42:02 +01:00
Hamish Knight
44bdd29b48 Revert "[AST] Allocate PlaceholderTypes in the correct arena"
This reverts commit 97be0424b4.
2023-05-05 19:43:08 +01:00
Hamish Knight
97be0424b4 [AST] Allocate PlaceholderTypes in the correct arena
We shouldn't be allocating placeholders for
type variables in the permanent arena, and we
should be caching them such that equality works.
2023-05-04 14:53:57 +01:00
Hamish Knight
aa72261ae2 Requestify raw and brief comment computation
Turn these ASTContext cached computations into
request evaluator cached computations.
2023-04-26 12:38:37 +01:00
Rintaro Ishizaki
a551c01d6a [Macros] Track plugin dependencies
* Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
* Insert 'DependencyTracker' to 'PluginLoader'
* Add dependencies right before loading the plugins

rdar://104938481
2023-04-25 10:50:32 -07:00
nate-chandler
0e8a6060ee Merge pull request #65306 from nate-chandler/rdar81421394
Address asserts raised when conforming pseudogeneric type to protocol with coroutine requirement.
2023-04-20 07:14:36 -07:00
Nate Chandler
b9ccde3771 SILFunctionType: Loosened assert.
Allowed SILFunctionType instances for pseudogeneric coroutines without
signatures to be created.  Such instances are created by
SILTypeSubstituter::substSILFunctionType when SILGen'ing a conformance
of a pseudogeneric type to a protocol featuring a coroutine requirement.

rdar://81421394
2023-04-19 17:53:15 -07:00
Artem Chikin
a5017db87a Merge pull request #65234 from artemcm/TestableDependencyOptionalLookup
[Dependency Scanning] Consider optional dependencies of `@testable` textual dependencies with an adjacent binary module
2023-04-19 08:41:45 -07:00
Doug Gregor
1bf924d938 Fix missing return on error path in loadExecutablePlugin(). 2023-04-18 18:11:26 -07:00
Doug Gregor
39438e31d1 [Compiler plugins] Fix missing return along error-handling paths
Fixes a crash when we cannot load a compiler plugin for some reason,
tracked by rdar://107797992.
2023-04-18 18:00:09 -07:00
Artem Chikin
6fcd8be072 [Dependency Scanning] Pull optional dependencies from the adjacent binary module for direct interface dependencies
For a `@Testable` import in program source, if a Swift interface dependency is discovered, and has an adjacent binary `.swiftmodule`, open up the module, and pull in its optional dependencies. If an optional dependency cannot be resolved on the filesystem, fail silently without raising a diagnostic.
2023-04-17 14:47:46 -07:00
Artem Chikin
e0eeb6339b [Dependency Scanning] Teach dependency scanner to resolve optional dependencies of a module 2023-04-17 13:36:53 -07:00
Dave Lee
39bb7bfe44 [AST] Convert ASTContext::getSwiftName to a free function
The only state `getSwiftName` uses is its argument, and can be made a free function. Of
note the inverse operation, `getKnownFoundationEntity`, is also a free function. This
removes the requirement that callers have an `ASTContext` instance.

(cherry-picked from commit fb524c0b86)
2023-04-14 11:43:13 -06:00
Rintaro Ishizaki
f99d70d181 [Macros] PluginRegistry vends 'LoadedLibraryPlugin' instead of 'void *'
`LoadedLibraryPlugin` is currently just a wrapper of `void` pointer from
`dlopen`. This will be convenient for abstracting platform specific
dynamic linrary handling.
2023-04-11 14:59:22 -07:00
Xi Ge
2836ee357b Frontend: pass down blocklist file paths from frontend options. NFC 2023-04-07 21:26:19 -07:00
Xi Ge
aa76845042 Merge branch 'main' into block-list 2023-04-05 12:21:40 -07:00
Xi Ge
2c2431e2da Frontend: add a frontend argument to pass down block list config file path 2023-04-05 12:20:49 -07:00
Steven Wu
09b8af86fb Virtualize swift compiler outputs (#63206)
Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
2023-04-05 23:34:37 +08:00
Doug Gregor
828de17b00 [Macros] Resolve macro names using unqualified lookup that ignores expansions
The macro name resolution in the source lookup cache was only looking at
macros in the current module, meaning that any names introduced by peer
or declaration macros declared in one module but used in another would
not be found by name lookup.

Switch the source lookup cache over to using the same
`forEachPotentialResolvedMacro` API that is used by lookup within
types, so we have consistent name-lookup-level macro resolution in both
places.

... except that would be horribly cyclic, of course, so introduce name
lookup flags to ignore top-level declarations introduced by macro
expansions. This is semantically correct because macro expansions are
not allowed to introduce new macros anyway, because that would have
been a terrible idea.

Fixes rdar://107321469. Peer and declaration macros at module scope
should work a whole lot better now.
2023-04-02 23:15:38 -07:00
Rintaro Ishizaki
59f744c36a [Macros] Track loaded plugin paths in each ASTContext
PluginRegistry is now shared between multiple ASTContext. ASTContext
should track its loaded plugin library paths separately.
2023-03-27 16:55:34 -07:00
John McCall
c041d1061a Perform component-wise substitution of pack expansions immediately.
Substitution of a pack expansion type may now produce a pack type.
We immediately expand that pack when transforming a tuple, a function
parameter, or a pack.

I had to duplicate the component-wise transformation logic in the
simplifyType transform, which I'm not pleased about, but a little
code duplication seemed a lot better than trying to unify the code
in two very different places.

I think we're very close to being able to assert that pack expansion
shapes are either pack archetypes or pack parameters; unfortunately,
the pack matchers intentionally produce expansions of packs, and I
didn't want to add that to an already-large patch.
2023-03-26 04:12:59 -04:00
John McCall
d16fed6e9a The canonical type of a pack expansion has a reduced shape. 2023-03-25 18:54:15 -04:00
Rintaro Ishizaki
d8c8574e9b [Macros] Load '-load-plugin-library' plugins lazily
* Argument to '-load-plugin-library' now must have a filename that's
  '{libprefix}{modulename}.{sharedlibraryextension}'
* Load '-load-plugin-library' plugins are now lazily loaded in
  'CompilerPluginLoadRequest'
* Remove ASTContext.LoadedSymbols cache because they are cached by
  'ExternalMacroDefinitionRequest' anyway
* `-load-plugin-executable` format validation is now in
  'ParseSearchPathArgs'
2023-03-24 14:11:24 -07:00
Rintaro Ishizaki
2a7f985ba3 Merge pull request #64555 from rintaro/macros-plugins-crashrecover
[Macros] Recovery after executable plugin crash
2023-03-24 10:01:03 -07:00
Rintaro Ishizaki
a49ab25ae8 [Macros] Recovery after executable plugin crash
When executable plugins crashed or somehow decided to exit, the compiler
should relaunch the plugin executable before sending another message.
2023-03-23 22:26:42 -07:00
Slava Pestov
17c1b352bb AST: Fix computation of RecursiveTypeProperties::HasParameterizedExistential 2023-03-23 00:53:13 -04:00
John McCall
7505a8a487 Merge pull request #64517 from rjmccall/arity-reabstraction-closures
Implement arity reabstraction for closures
2023-03-22 14:14:23 -04:00
John McCall
77ac9db3ff [NFC] Add a function to induce a pack type from a slice of CanParams. 2023-03-21 14:19:08 -04:00
Rintaro Ishizaki
93e25d2935 Merge pull request #64376 from rintaro/macros-plugin-server 2023-03-20 07:52:08 -07:00
Konrad `ktoso` Malawski
e0877594da [Concurrency] Custom executors with move-only Job (#63569) 2023-03-18 14:02:43 +09:00
Rintaro Ishizaki
b2542a7ce9 [Macros] Small review changes
* New struct to store a pair of plugin search path and the server path
* typo
2023-03-17 19:15:06 -07:00
Rintaro Ishizaki
c4b3edd6df [Macros] Add swift-plugin-server executable
This executable is intended to be installed in the toolchain and act as
an executable compiler plugin just like other 'macro' plugins.

This plugin server has an optional method 'loadPluginLibrary' that
dynamically loads dylib plugins.
The compiler has a newly added option '-external-plugin-path'. This
option receives a pair of the plugin library search path (just like
'-plugin-path') and the corresponding "plugin server" path, separated
by '#'. i.e.

  -external-plugin-path
    <plugin library search path>#<plugin server executable path>

For exmaple, when there's a macro decl:

  @freestanding(expression)
  macro stringify<T>(T) -> (T, String) =
      #externalMacro(module: "BasicMacro", type: "StringifyMacro")

The compiler look for 'libBasicMacro.dylib' in '-plugin-path' paths,
if not found, it falls back to '-external-plugin-path' and tries to find
'libBasicMacro.dylib' in them. If it's found, the "plugin server" path
is launched just like an executable plugin, then 'loadPluginLibrary'
method is invoked via IPC, which 'dlopen' the library path in the plugin
server. At the actual macro expansion, the mangled name for
'BasicMacro.StringifyMacro' is used to resolve the macro  just like
dylib plugins in the compiler.

This is useful for
 * Isolating the plugin process, so the plugin crashes doesn't result
   the compiler crash
 * Being able to use library plugins linked with other `swift-syntax`
   versions

rdar://105104850
2023-03-16 14:00:45 -07:00
John McCall
48ccef7cde [NFC] Store the list of opened pack parameters as a flat array in
opened generic environments

Finding these is very hot for these environments, so doing it once
is a pretty nice win in both speed and code complexity.

I'm not actually using this yet.
2023-03-15 17:27:04 -04:00
John McCall
09018a8981 [NFC] Store interface shape types in opened element environments 2023-03-15 17:25:04 -04:00
Kavon Farvardin
a8a44ebb17 Merge pull request #64106 from kavon/enable-moveonly-by-default
Enable moveonly / noncopyable types by default
2023-03-15 09:59:29 -07:00
Kavon Farvardin
12d33b2b84 run the move-checker if lexical borrow scopes are enabled
this pulls just the move checking passes out from
behind the experimental flag.
2023-03-13 22:39:31 -07:00