Commit Graph

1958 Commits

Author SHA1 Message Date
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
Hamish Knight
c1d6f1c5d5 Better enforce GenericFunctionType TypeVariableType invariant
Enforce that we don't have any type variables
present in either the result or parameter types.
To ensure the constraint system doesn't violate
this invariant, refactor `getTypeOfMemberReference`
slightly to avoid construction of a
`GenericFunctionType` as a means of opening the
generic parameters of the context for a VarDecl.
2023-03-13 22:08:07 +00:00
Slava Pestov
71e40317b3 AST: Remove PackArchetypeType::getSingletonPackType() 2023-03-07 23:19:25 -05:00
John McCall
dc477a0fd2 Merge pull request #64167 from rjmccall/variadic-results
Implement the caller side of return types containing variadic packs
2023-03-07 11:20:46 -05:00
John McCall
bb05a0edc1 Add a convenience API to build canonical pack types from slices
of canonical tuple type elements.

This has come up more than you might think.
2023-03-07 03:15:31 -05:00
Holly Borla
e7f82bc6e7 [ConstraintSystem] Record both the UUID and the shape class for opened pack
element environments.

This allows the constraint system to ensure that for a given pack expansion locator,
the given shape class is always the same when requesting the element environment.
If the shape class differs, it means there's a same-shape requirement failure, which
will be diagnosed via the ShapeOf constraint simplification.
2023-03-06 21:22:35 -08:00
John McCall
d7123c7e65 Merge pull request #64135 from rjmccall/variadic-generic-callee-results
Implement the callee side of returning a tuple containing a pack expansion
2023-03-06 11:11:47 -05:00
Richard Wei
19335a1dcf Merge pull request #64137 from rxwei/macro-loaded-module-trace-take-2 2023-03-06 07:07:54 -08:00
Egor Zhdan
ac72084854 Merge pull request #63683 from apple/egorzhdan/cxx-optional
[cxx-interop] Add `CxxOptional` protocol for `std::optional` ergonomics
2023-03-06 10:43:05 +00:00
Richard Wei
c6139f2f78 [Macros] Emit loaded module trace for plugins loaded from search paths
When loading plugins from `-plugin-path`, use the global `PluginRegistry` to keep a record of what's loaded. Emit these dependencies to the loaded module trace.
2023-03-06 02:19:56 -08:00
John McCall
157be3420c Implement the callee side of returning a tuple containing a pack expansion.
This required quite a bit of infrastructure for emitting this kind of
tuple expression, although I'm not going to claim they really work yet;
in particular, I know the RValue constructor is going to try to explode
them, which it really shouldn't.

It also doesn't include the caller side of returns, for which I'll need
to teach ResultPlan to do the new abstraction-pattern walk.  But that's
next.
2023-03-06 04:26:18 -05:00
Holly Borla
ebcd444945 [ASTVerifier] Move PackExpansionType::get assertions into the ASTVerifier.
These assertions are violated for invalid code, so let's only check these on
a well-formed AST.
2023-03-05 00:09:07 -08:00
Egor Zhdan
a12986ade4 [cxx-interop] Add CxxOptional protocol for std::optional ergonomics
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::optional` when used from Swift code.

As of now, the overlay adds an initializer of `Swift.Optional` that takes an instance of `CxxOptional` as a parameter.
2023-03-03 19:41:30 +01:00
John McCall
b3b90a82be Merge pull request #64048 from rjmccall/variadic-pack-expansion-arguments
Implement the emission of pack expansion arguments in SILGen
2023-03-03 11:46:00 -05:00
John McCall
06a7468e4f Implement the emission of pack expansion arguments in SILGen
Mostly fixing some existing code.
2023-03-03 02:52:32 -05:00
Joe Groff
5345e982e9 Only mangle borrowing/consuming when they would change ABI.
`__shared` and `__owned` would always get mangled, even when they don't have any effect
on ABI, making it unnecessarily ABI-breaking to apply them to existing API to make
calling conventions explicit. Avoid this issue by only mangling them in cases where they
change the ABI from the default.
2023-03-02 21:33:29 -08:00
Joe Groff
17c803724f Implement consuming and borrowing declaration-level modifiers from SE-0377.
`borrowing func`/`consuming func` control the ownership convention of `self` for
methods.
2023-03-01 11:58:59 -08:00