Commit Graph

28352 Commits

Author SHA1 Message Date
Allan Shortlidge
4ed62e3154 AST: Introduce Decl::getAvailableAttrForPlatformIntroduction().
It replaces `AvailabilityInference::attrForAnnotatedAvailableRange()`.
2025-01-07 07:31:12 -08:00
Hamish Knight
33bff48e92 Merge pull request #78367 from hamishknight/in-context
[Sema] Remove RecontextualizeClosures
2025-01-07 09:43:27 +00:00
Anthony Latsis
33f03f7a03 Merge pull request #78434 from AnthonyLatsis/each-pack
Sema: Do better at diagnosing missing `each`
2025-01-07 09:11:28 +00:00
Anthony Latsis
32cf2d8c2f Sema: Do better at diagnosing missing each 2025-01-07 05:22:48 +00:00
Pavel Yaskevich
b7a7839ed0 [CSSimplify] Allow any Sendable -> Any if subscript appears in preconcurrency context 2025-01-06 19:41:57 -08:00
Pavel Yaskevich
c225db473c [CSApply] NFC: Simplify coerceSelfArgumentToType
`coerceToType` can to handle l-value -> inout correctly
and report better information if coercion fails.
2025-01-06 18:11:36 -08:00
Ian Anderson
87d6979dae Merge pull request #78303 from ian-twilightcoder/clang-importer-search-paths
[ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
2025-01-06 13:05:25 -08:00
Slava Pestov
2d17294d73 Merge pull request #78301 from slavapestov/remove-one-way-constraints
Sema: Remove ConstraintKind::OneWayBindParam and ConstraintKind::OneWayEqual
2025-01-05 10:38:14 -05:00
Anthony Latsis
062061e37a Merge pull request #78235 from AnthonyLatsis/aloe-vera
Sema: Minor adjustment to `BindingSet` dumping
2025-01-04 15:13:10 +00:00
Anthony Latsis
a6e5e19512 Sema: Minor adjustment to BindingSet dumping
Shorten some of the keys and format them consistently as sentence
fragments rather than identifiers.
2025-01-04 11:27:54 +00:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Allan Shortlidge
2c52f057df Merge pull request #78414 from tshortli/back-deployed-without-body-redux
Sema: Diagnose `@backDeployed` functions with missing bodies in swiftinterfaces
2025-01-03 15:16:44 -08:00
Allan Shortlidge
7ea778f3a0 Sema: Diagnose @backDeployed functions with missing bodies in swiftinterfaces.
A `@backDeployed` function printed in a `.swiftinterface` must have a function
body so that SILGen can emit a fallback copy to call when the back deployed
function is unavailable. Previously, the compiler would crash in SILGen when
compiling an interface containing a back deployed function without a body.

Resolves rdar://141593108.
2025-01-03 09:15:12 -08:00
Joe Groff
31b702d590 Merge pull request #78311 from jckarter/addressable-for-dependencies
Add an `@_addressableForDependencies` type attribute.
2025-01-03 07:45:43 -08:00
Pavel Yaskevich
5cac7dba79 Merge pull request #78357 from xedin/too-complex-with-count
[CSOptimizer] Few tweaks to make unapplied disjunction and literal array arguments faster
2025-01-03 00:20:40 -08:00
Joe Groff
5c4406b5e8 Add an @_addressableForDependencies type attribute.
This attribute makes it so that a parameter of the annotated type, as well as
any type structurally containing that type as a field, becomes passed as
if `@_addressable` if the return value of the function has a dependency on
the parameter. This allows nonescapable values to take interior pointers into
such types.
2025-01-02 21:33:51 -08:00
Michael Gottesman
56f38c4172 [concurrency] Add support in SILGen/SIL for emitting and calling implicit leading parameters for CallerInheritingIsolation isolation.
This does not change region isolation yet to recognize these as effectively
nonisolated.
2025-01-02 13:18:54 -08:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
Michael Gottesman
b2a4f7e3cc [sil] Add to SIL and SILGen the ability to emit/represent implicit parameters.
I need this today to add the implicit isolated parameter... but I can imagine us
adding more implicit parameters in the future, so it makes sense to formalize it
so it is easier to do in the future.
2025-01-02 13:18:11 -08:00
Hamish Knight
4cbe481f82 Merge pull request #78377 from hamishknight/no-simplify-result
[CS] Don't simplify `FunctionResult` in `simplifyLocator`
2025-01-02 17:26:22 +00:00
Doug Gregor
7d6e3776ba Merge pull request #78332 from DougGregor/strict-safety-improvements
Strict safety improvements
2025-01-02 08:25:02 -08:00
Anthony Latsis
5c24df22a0 Merge pull request #78363 from AnthonyLatsis/dicksonia-arborescens
[NFC] Sema: Tidy up `canOpenExistentialCallArgument`
2025-01-02 15:38:27 +00:00
Anthony Latsis
248c3aff5e Merge pull request #78320 from AnthonyLatsis/nymphaea-rubra
Sema: Small `matchPackExpansionTypes` cleanup
2025-01-02 12:01:13 +00:00
Anthony Latsis
9dad512515 Merge pull request #78356 from AnthonyLatsis/tuber-melanosporum
Sema: Minor QoI improvements for existential `any` diagnosis
2025-01-02 11:58:34 +00:00
Hamish Knight
9fb064ad2c [CS] Remove resolveInterfaceType
Use `simplifyType` instead with the new parameter
for getting an interface type. Also avoid using
`resolveInterfaceType` in CSApply since we don't
need the opened generic parameter mapping behavior.
2024-12-31 18:39:20 +00:00
Hamish Knight
9fe4abc6fd [CS] Simplify Solution::resolveInterfaceType
Rather than attempting to re-implement `simplifyType`,
tweak `Solution::simplifyType` such that it can
map the resulting type out of context, and can
turn type variables into their opened generic
parameters.
2024-12-31 18:39:19 +00:00
Hamish Knight
2fd6863b1d [CS] Remove AutoClosureForwarding fix
The fix is currently unused, and the
FailureDiagnostic can be inlined into
MissingCallFailure.
2024-12-29 12:25:19 +00:00
Hamish Knight
86e8165569 [CS] Don't simplify FunctionResult in simplifyLocator
Simplifying into the function expression is wrong,
like `FunctionArgument` this isn't an element that
can be simplified. This also means we don't need
to handle it in `MissingCallFailure`, since we
shouldn't be recording that fix in this case.
2024-12-29 12:25:18 +00:00
Hamish Knight
2c2038d459 [CS] Allow InsertExplicitCall for higher-order functions
Allow `InsertExplicitCall` for e.g converting
`() -> () -> Void` to `() -> Void`. No test since
it's already covered in the test suite when the
next commit is applied.
2024-12-29 12:25:18 +00:00
Hamish Knight
6a1f8c7265 [Sema] Re-parent AccessorDecls for local vars too
Make sure we walk into any non-DeclContext decl,
allowing us to e.g walk into VarDecls to correctly
re-contextualize their accessors in an outer
autoclosure. I don't *think* this currently makes
much of a difference since the mangling today uses
the DeclContext of the VarDecl, but it seems like
the right thing to do regardless.
2024-12-27 14:44:56 +00:00
Hamish Knight
19938632cd [Sema] Remove RecontextualizeClosures
Merge with ContextualizeClosuresAndMacros, and
rename to ContextualizationWalker given that it
re-contextualizes a whole bunch of AST nodes now.
This ensures we correctly handle cases such as
decls in if/switch expressions within autoclosures.
2024-12-27 14:44:56 +00:00
Hamish Knight
5d631990bb [Sema] Avoid walking lazy inits in ContextualizeClosuresAndMacros
We want these to be contextualized as part of
their implicit getter, avoid attempting to
contextualize as part of the PatternBindingDecl.
This avoid incorrectly computing captures as part
of the PatternBindingDecl; as such we also need
to update ActorIsolationChecker to walk lazy inits
as part of the accessor.
2024-12-27 14:44:55 +00:00
Hamish Knight
61393dee3a [Sema] NFC: Clean up the entrypoint to ContextualizeClosuresAndMacros
Expose a generic `TypeChecker::contextualizeExpr`
to invoke it.
2024-12-27 14:44:55 +00:00
Hamish Knight
a0c328617e [Sema] NFC: Clean up FindCapturedVars lazy init walking
We want to walk the lazy initializer in the
accessor, but when this code was written that
wasn't a walking option. Switch to using
`LazyInitializerWalking::InAccessor`.
2024-12-27 14:44:55 +00:00
Doug Gregor
0d8b67e70c Fix substitutions for generic requirements 2024-12-26 10:21:44 -08:00
Pavel Yaskevich
8a304f88c6 [CSOptimizer] Extend candidate/parameter matching to support array literals
Match `[...]` to Array<...> and/or `ExpressibleByArrayLiteral`
conforming types. This is very helpful for expressions like:
`[...] + [...]`.
2024-12-25 12:51:01 -08:00
Anthony Latsis
56d943a77e [NFC] Sema: Tidy up canOpenExistentialCallArgument 2024-12-25 02:25:28 +00:00
Pavel Yaskevich
0737542da8 [CSOptimizer] Favor choices that don't require application
When disjunction is not applied, don't only bump its score
but also favor all of the choices that don't require application
because selection algorithm uses that for comparison.

This is important for situation when property is overload with
a method i.e. `Array.count`.
2024-12-24 17:12:36 -08:00
Doug Gregor
92fbedcbc0 Factor the strict memory safety checking declarations into their own header 2024-12-24 09:43:50 -08:00
Anthony Latsis
fc1ad79ddd [NFC] ConstraintSystem: Rename openExistentialType to openAnyExistentialType
This method can open an existential metatype too, and we already use
`isAnyExistentialType` to mean "existential type or existential
metatype"
2024-12-24 17:42:54 +00:00
Doug Gregor
4b3c18de41 Account for implicit unsafety in unsafe witness and override checks
When a witness is unsafe and its corresponding requirement is not
unsafe, the conformance itself needs to be determined to be unsafe.
When doing this check, account for the fact that the requirement might
be implicitly unsafe, i.e., it uses unsafe types. In such cases, the
requirement is effectively unsafe, so the unsafe witness to it does not
make the conformance unsafe. Therefore, suppress the diagnostic. This
accounts for cases where the protocol comes from a module that didn't
enable strict memory safety checking, or didn't suppress all warnings
related to it, as well as cases where substitution of type witnesses
introduces the unsafe type.

The same thing occurs with overriding a method: an unsafe override of
a method that involves unsafe types (but was not marked @unsafe for
whatever reason) does not make the subclassing itself unsafe, so don't
diagnose it as such.
2024-12-24 09:32:05 -08:00
Doug Gregor
ba23f36f3e Diagnose the use of a typealias that involves unsafe types
As we do when referencing other kinds of declarations, if a
typealias isn't `@unsafe`, but it involves unsafe types,
diagnose the non-safety at the point of reference.
Fixes https://github.com/swiftlang/swift/issues/78220
2024-12-24 08:36:24 -08:00
Ian Anderson
cdb42c3535 [ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
When Swift passes search paths to clang, it does so directly into the HeaderSearch. That means that those paths get ordered inconsistently compared to the equivalent clang flag, and causes inconsistencies when building clang modules with clang and with Swift. Instead of touching the HeaderSearch directly, pass Swift search paths as driver flags, just do them after the -Xcc ones.

Swift doesn't have a way to pass a search path to clang as -isystem, only as -I which usually isn't the right flag. Add an -Isystem Swift flag so that those paths can be passed to clang as -isystem.

rdar://93951328
2024-12-23 22:15:52 -08:00
Anthony Latsis
f1989607ad TypeCheckType: Mark misspelled optional existential as invalid
So that is does not show up in other diagnostic passes
2024-12-23 21:55:58 +00:00
Doug Gregor
aab36f63f2 Revert "Sema: Diagnose @backDeployed functions with missing bodies in swiftinterfaces" 2024-12-21 21:53:46 -08:00
Pavel Yaskevich
80a988e3bc [CSGen] forcing an optional should prefer subtyping only if it's applied to a member
`TVO_PrefersSubtypeBinding` in this case is intended to support
references to Objective-C imported members that can be force
unwrapped before being used i.e. accessing an overloaded method
on `AnyObject` should always prefer an overload that returns
a subtype:

```
@objc class A: NSObject {
    @objc func test() -> A { }
    @objc func test() -> B { }
}

func test(obj: AnyObject) {
  obj.test!()
}
```

where `B` is a subtype of `A` should result in selection of
`() -> B`.
2024-12-21 00:42:13 -08:00
Pavel Yaskevich
a892e571b6 [CSSimplify] Retry member lookup on an insufficiently resolved optional base in diagnostic mode
Re-introduce unsolved member constraint when optional object is
a type variable or member until it's bound, otherwise it's impossible
to tell whether unwrapped base would have a member or not.
2024-12-21 00:42:13 -08:00
Pavel Yaskevich
e7a9bcb303 [TypeChecker] Type-check where clauses for for-in statements separately
Instead of using `one-way` constraints, just like in closure contexts
for-in statements should type-check their `where` clauses separately.

This also unifies and simplifies for-in preamble handling in the
solver.
2024-12-21 00:42:13 -08:00
Slava Pestov
25ad700fb0 Sema: Simplify depthFirstSearch() a bit now that it only has one caller 2024-12-21 00:42:13 -08:00
Slava Pestov
9fb6d9251e Sema: Remove DependentComponentSplitterStep 2024-12-21 00:42:13 -08:00