rather than relying on PackElementExprs collected by preCheck.
This handles pack element expressions and pack element type reprs, and enforces that
all packs expanded by a given pack expansion expression all have the same shape.
Once the parser creates PackExpansionExpr directly (based on a dedicated syntax instead
of postfix '...'), the code in preCheck for identifying and creating pack expansions
can simply be deleted.
of assigning it to std::function_ref.
std::function_ref does not own the function reference, so assigning an OpenPackElementType
to a local function_ref lead to stale constraint system references when invoking
operator () later on.
constraints, vend potential bindings through PotentialBindings::infer.
This allows for bidirectional binding inference from the pack type to the
element type and vice versa.
Enable type checking support for explicitly specifying generic arguments to
a macro, e.g., `#stringify<Double>(1 + 2)`. To do so, introduce a new
kind of constraint that performs explicit argument matching against the
generic parameters of a macro only after the overload is chosen.
generating constraints for PackExpansionExpr.
The result pattern type of a pack expansion doesn't always contain pack
references. Instead, use the type of the first pack reference binding.
`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
Rather than lookup up the macro by name again during constraint
application, use the overload choice for the macro as recorded in the
constraint system to apply the correct macro.
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
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
During prechecking, postfix '...' expressions are rewritten to pack
expansion expressions if the operand contains pack references. References
to packs are replaced with opaque values, and the pack expansion stores
the opaque value bindings to decl refs.
Introduce `MacroExpansionExpr` and `MacroExpansionDecl` and plumb it through. Parse them in roughly the same way we parse `ObjectLiteralExpr`.
The syntax is gated under `-enable-experimental-feature Macros`.
Update `applyPropertyWrapperToParameter` to set types to projected
and wrapped values and allow `TypeVariableRefFinder` to skip decls
with implicit property wrappers that are not yet resolved.