Previously, if a request R evaluated itself N times, we would emit N
"circular reference" diagnostics. These add no value, so instead let's
cache the user-provided default value on the first circular evaluation.
This changes things slightly so that instead of returning an
llvm::Expected<Request::OutputType>, various evaluator methods take
a callback which can produce the default value.
The existing evaluateOrDefault() interface is unchanged, and a new
evaluateOrFatal() entry point replaces
llvm::cantFail(ctx.evaluator(...)).
Direct callers of the evaluator's operator() were updated to pass in
the callback. The benefit of the callback over evaluateOrDefault() is
that if the default value is expensive to constuct, like a dummy
generic signature, we will only construct it in the case where a
cycle actually happened, otherwise we just delete the callback.
(cherry picked from commit b8fcf1c709efa6cd28e1217bd0efe876f7c0d2b7)
Test shadowed variable of same type
Fully type check caller side macro expansion
Skip macro default arg caller side expr at decl primary
Test macro expand more complex expressions
Set synthesized expression as implicit
Add test case for with argument, not compiling currently
Test with swiftinterface
Always use the string representation of the default argument
Now works across module boundary
Check works for multiple files
Make default argument expression work in single file
Use expected-error
Disallow expression macro as default argument
Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.
Resolves rdar://121409846
Don't delete the OS declaration of `exit` because the concurrency shims aren't always imported, and so the shim declaration might not always be available.
Don't override the OS declaration of `exit` in the concurrency shims since we can't just delete the OS one. Instead, set up internal shims just for building Concurrency that forward declares `exit`.
When SILGen was emitting the stored initializer function, it updated the location to a new autogenerated location tied to the initialization expression. That in turn reset the function's parent module to null, as the initialization expression is not a decl, and thus it didn't produce a decl context SIL could use when looking for the parent module. That lead to a this function having no parent module when it was serialized, and thus a user that used this function from code in another Swift module thought that this function should use 'dllimport' on Windows, even when the parent module was built with as the static library (i.e. using the -static flag). This lead to spurious LNK4217 diagnostics when building the Swift package manager using CMake on windows. This change fixes that by preserving the parent module for such function.
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.
Also renames `TypeDecl::isEscapable` to match.
Type-checking and SILGen for non-inlinable functions is skipped in the
presence of `-experimental-skip-non-inlinable-function-bodies` and
`-experimental-skip-non-inlinable-function-bodies-without-types` flags.
Such functions may be top-level and may contain captures (if they appear
after a `guard` statement), for which we were setting the type expansion
context during SILGen. Setting type expansion context however, relied on
the capture info being computed -- which was never happening because of
the abovementioned flags.
Changes in this commit make setting type expansion context, for
captures, conditional on a flag that ensures that the function has already
been typechecked.
Fixes#57646
This allows calling a C++ function with default arguments from Swift without having to explicitly specify the values of all arguments.
rdar://103975014
SILGen and IRGen would disagree on the return type of the
`swift_task_getMainExecutor()` runtime function if
`SILGenModule::getGetMainExecutor()` had ever been called. To address this,
consistently use the `buildMainActorExecutorRef` built-in and get rid of
`SILGenModule::getGetMainExecutor()`.
Resolves rdar://116472583
When `-experimental-skip-non-exportable-decls` is specified, skip emitting
property wrapper backing inits since they cannot be referenced directly by
module clients.
Resolves rdar://119469651
Previously, the initializer expressions of lazy vars would only be marked as
subsumed when the getter body for the var was synthesized. This didn't work
with `-experimental-lazy-typechecking` since accessor synthesis was not
guaranteed to happen. Consequently, SILGen would emit the initializer even
though it was already subsumed and then assert/crash since the init had also
not been checked and contextualized. Now lazy var inits are marked subsumed in
the request creating storage.
Resolves rdar://118421753
As a follow up to https://github.com/apple/swift/pull/69841, clarify the
possible states that initializer expression of a pattern can be in. The
possible states are not checked, checked, and "checked and contextualized"
(which is the new state that was introduced and requestified in the previous
PR). This refactoring encodes the states more explicitly and renames a few
compiler APIs to better align with the new naming. NFC.
Allow initializer expressions to be emitted during SILGen when
`-experimental-lazy-typecheck` is specified by introducing a new request that
fully typechecks the init expressions of pattern binding declarations
on-demand.
There are still a few rough edges, like missing support for wrapped properties
and incomplete handling of subsumed initializers. Fixing these issues is not an
immediate priority because in the short term `-experimental-lazy-typecheck`
will always be accompanied by `-enable-library-evolution` and
`-experimental-skip-non-exportable-decls`. This means that only the
initializers of properties on `@frozen` types will need to be emitted and
property wrappers are not yet fully supported on properties belonging to
`@frozen` types.
Resolves rdar://117448868
When -experimental-skip-non-exportable-decls is specified, the SIL for the
initializers of stored properties is unneeded and should be skipped so long as
the property does not belong to a `@frozen` type.
Functions that are nested within other functions are not exportable to clients
since they cannot be called directly by clients. However, they need still to be
emitted during SILGen when -experimental-skip-non-exportable-decls is specified
so walk the decl context hierarchy when determining whether to skip emitting a
function.
Resolves rdar://117440503
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.
Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
Function bodies are skipped during typechecking when one of the
-experimental-skip-*-function-bodies flags is passed to the frontend. This was
implemented by setting the "body kind" of an `AbstractFunctionDecl` during decl
checking in `TypeCheckDeclPrimary`. This approach had a couple of issues:
- It is incompatible with skipping function bodies during lazy typechecking,
since the skipping is only evaluated during a phase of eager typechecking.
- It prevents skipped function bodies from being parsed on-demand ("skipped" is
a state that is distinct from "parsed", when they ought to be orthogonal).
This needlessly prevented complete module interfaces from being emitted with
-experimental-skip-all-function-bodies.
Storing the skipped status of a function separately from body kind and
requestifying the determination of whether to skip a function solves these
problems.
Resolves rdar://116020403
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.
Also, improve naming and documentation for these queries.
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.
We want people to use getInterfaceType() like with the other decl kinds.
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.