Commit Graph

28941 Commits

Author SHA1 Message Date
Pavel Yaskevich
29b04f4a63 [CSSimplify] SE-0324: Use correct conversion when converting array types
If the argument type is an array and it's passed to an imported declaration
that accepts a raw pointer, the solver should use an "array-to-c-pointer"
conversion instead of the one for pointers.

Resolves: rdar://158629300
2025-08-21 15:38:17 -07:00
Hamish Knight
303c1ee951 Merge pull request #83803 from hamishknight/err-fallback 2025-08-20 10:13:23 +01:00
Hamish Knight
5c3f6703a0 Remove diag::type_of_expression_is_ambiguous
This is a diagnostic that is only really emitted as a fallback when
the constraint system isn't able to better diagnose the expression.
It's not particulary helpful for the user, and can be often be
misleading since the underlying issue might not actually be an
ambiguity, and the user may well already have a type annotation. Let's
instead just emit the fallback diagnostic that we emit in all other
cases, asking the user to file a bug.
2025-08-19 17:14:23 +01:00
Egor Zhdan
3d3331f1c6 Merge pull request #83787 from egorzhdan/egorzhdan/weak-reference
[cxx-interop] Prohibit weak references to foreign reference types
2025-08-19 12:15:38 +01:00
Egor Zhdan
9abadf5483 [cxx-interop] Prohibit weak references to foreign reference types
This fixes a runtime crash when a `weak` reference to a C++ foreign reference type is used.

Instead of a runtime crash, Swift would now emit a compiler error saying that `weak` keyword is incompatible with foreign reference types.

rdar://124040825 / resolves https://github.com/swiftlang/swift/issues/83080
2025-08-18 18:08:43 +01:00
Doug Gregor
4ff65cc244 Merge pull request #83784 from DougGregor/never-emit-into-client
Add @_neverEmitIntoClient to prohibit SIL serialization for a function
2025-08-18 04:19:59 -07:00
Pavel Yaskevich
a5649a12e5 Merge pull request #83735 from xedin/rdar-158159462
[CSOptimizer] Add support for opened existential arguments
2025-08-18 00:16:24 -07:00
Doug Gregor
2f60d729f0 Add @_neverEmitIntoClient to prohibit SIL serialization for a function
Part of the Embedded Swift linkage model, this attribute ensures that
the function it applies to has a strong definition in its owning
module, and that its SIL is never serialized. That way, other modules
will not have access to its definition.

Implements rdar://158364184.
2025-08-17 23:21:57 -07:00
Hamish Knight
89feb8fabb [Diags] Remove some now unnecessary calls to flush 2025-08-17 11:48:21 +01:00
Slava Pestov
a983323508 Merge pull request #83768 from slavapestov/replace-covariant-result-type
Sema: Remove a bunch of usages of replaceCovariantResultType()
2025-08-16 08:56:12 -04:00
Hamish Knight
89787e24b6 Merge pull request #83766 from hamishknight/fifty-thousand-ants
[CS] Use apply component locator for `verifyThatArgumentIsHashable`
2025-08-16 05:20:51 +01:00
Slava Pestov
d93b120e24 Sema: Remove usage of replaceCovariantResultType() in CSApply 2025-08-15 18:37:15 -04:00
Slava Pestov
1fbdc20be1 Sema: Remove usage of replaceCovariantResultType() in CSApply 2025-08-15 18:37:15 -04:00
Slava Pestov
9be81d0302 Sema: Clean up ConstraintSystem::getTypeOfReference() 2025-08-15 18:37:12 -04:00
Slava Pestov
eb56862e66 Sema: Clean up getMemberReferenceTypeFromOpenedType() 2025-08-15 18:37:12 -04:00
Hamish Knight
4423399fce [CS] Use apply component locator for verifyThatArgumentIsHashable
For a method key path use the locator for the apply itself rather
than the member, ensuring we handle invalid cases where the apply is
the first component, and providing more accurate location info.
2025-08-15 21:30:22 +01:00
Hamish Knight
61d0486d12 [CS] NFC: Factor out hasKeyPathComponent 2025-08-15 21:30:22 +01:00
Slava Pestov
a399c46db7 Sema: Pull preconcurrency adjustment out of getUnopenedTypeOfReference() 2025-08-15 14:39:14 -04:00
Pavel Yaskevich
0d33af78ca [CSOptimizer] Add support for opened existential arguments
Check whether it would be possible to match a parameter type
by opening an existential type of the candidate argument.

Resolves: rdar://158159462
2025-08-15 00:14:51 -07:00
Slava Pestov
4146a7f935 Merge pull request #83736 from slavapestov/fix-rdar157329046
Sema: New opaque return type circularity check that doesn't trigger lazy type checking of bodies
2025-08-14 23:46:01 -04:00
Mykola (Nickolas) Pokhylets
31470bbd1e Merge pull request #82732 from nickolas-pohilets/mpokhylets/weak-let-feature
Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved
2025-08-14 23:59:28 +02:00
Slava Pestov
501b21d749 Sema: Micro-optimize adjustFunctionTypeForConcurrency() 2025-08-14 17:01:47 -04:00
Slava Pestov
e26034b7ac Sema: New opaque return type circularity check that doesn't trigger lazy type checking of bodies
Commit b70f8a82b1 introduced a usage of
ReplaceOpaqueTypesWithUnderlyingTypes in Sema. Previously this was only
called from SILGen.

The problem was that ReplaceOpaqueTypesWithUnderlyingTypes would call
getUniqueUnderlyingTypeSubstitutions(), which triggers a request to
type check the body of the referenced function.

While this didn't result in unnecessary type checking work, because
UniqueUnderlyingTypeSubstitutionsRequest::evaluate() would skip bodies
in secondary files, it did change declaration checking order.

The specific issue we saw was a bad interaction with associated type
inference and unqualified lookup in a WMO build, and a complete test
case is hard to reduce here.

However, no behavior change is intended with this change, modulo bugs
elsewhere related to declaration checking order, so I feel OK not adding
a test case.

I'll hopefully address the unqualified lookup issue exposed in the
radar soon; it has a reproducer independent of opaque return types.

Fixes rdar://157329046.
2025-08-14 17:01:47 -04:00
Pavel Yaskevich
90224bf927 [Typechecker/OpenedExistentials] NFC: Extract some checks from canOpenExistentialCallArgument into a separate function
Some of the logic of `canOpenExistentialCallArgument` has to be
shared with constraint optimizer which does it's own validation
and most importantly - doesn't open overload choice type.

In order to share the logic between the solver and the optimizer,
let's extract checking that determines whether it's possible to
open existential argument into `canOpenExistentialAt`.
2025-08-14 13:58:01 -07:00
Pavel Yaskevich
030564b9db Merge pull request #83703 from xedin/rdar-157644867
[CSOptimizer] All the candidates should match `Any` parameter type
2025-08-14 13:20:12 -07:00
Hamish Knight
af73ca374d Merge pull request #83704 from hamishknight/fix-stress-tester-regression
[CS] Record `SkipUnhandledConstructInResultBuilder` for completion
2025-08-14 20:39:36 +01:00
Allan Shortlidge
eea4189f99 Merge pull request #83718 from tshortli/dont-automatically-apply-dynamic-member-lookup-subscript-access-fix-it 2025-08-14 07:17:13 -07:00
Allan Shortlidge
5e2dfdf4e6 Merge pull request #83714 from tshortli/allow-obsolete-in-swift-overrides 2025-08-14 07:16:50 -07:00
Hamish Knight
eb7aa6281c [CS] Record SkipUnhandledConstructInResultBuilder for completion
We still want to record this fix when falling back to type-checking
as a regular function body to ensure that in cases where there is a
disjunction of multiple result builders we favor the one that actually
supports the body.
2025-08-14 11:57:11 +01:00
Allan Shortlidge
db117bfefe Sema: Don't apply access level fix-it to @dynamicMemberLookup subscript.
The adjusted access level for the subscript shouldn't be fixed automatically
since sometimes the diagnostic is a warning and other times automatically
applying the fix-it immediately causes other errors, which can be confusing.

Resolves rdar://158261884.
2025-08-13 23:13:07 -07:00
Allan Shortlidge
550d7bb754 Sema: Allow overrides to be unavailable in the current Swift language mode.
Fixes a regression from https://github.com/swiftlang/swift/pull/83354.

Resolves rdar://158262522
2025-08-13 17:57:05 -07:00
Pavel Yaskevich
c46f9e4f45 [CSOptimizer] All the candidates should match Any parameter type
If the parameter is `Any` we assume that all candidates are
convertible to it, which makes it a perfect match. The solver
would then decide whether erasing to an existential is preferable.

Resolves: rdar://157644867
2025-08-13 14:59:54 -07:00
Hamish Knight
5e27e83456 Merge pull request #83613 from hamishknight/next-step
[IDE] Perform extension binding after AST mutation
2025-08-13 22:37:56 +01:00
Pavel Yaskevich
32b97d0e2a [TypeCheckEffects] AbstractFunction: Parameter types should be mapped into context
Parameter type could be represented by an associated type which is
bound to a concrete type by an extension, `AbstractFunction::getType()`
should map it into context before returning because the construct is
that it always produces a function type.

Resolves: rdar://156955193
2025-08-12 17:29:07 -07:00
Hamish Knight
ead2c0c43a Merge pull request #83634 from hamishknight/invalid-check 2025-08-12 09:36:22 +01:00
Hamish Knight
d1fb307c6d Merge pull request #83632 from hamishknight/complete-result
[CS] Better handle unsupported result builder elements for completion
2025-08-11 22:33:14 +01:00
Hamish Knight
e7098a34b2 [Sema] Remove isInvalid checks from checkAndContextualizePatternBindingInit
The invalid bit on PatternBindingDecl is very coarse grained, it
means any of the possible binding entries could be invalid.
Contextualization can handle invalid code anyway (e.g this is what we
do for `typeCheckBody`), so let's just avoid checking.
2025-08-11 12:55:36 +01:00
Hamish Knight
dad7c26bcd [CS] Always set ErrorType for exprs in markInvalid
I don't recall why I made this conditional, let's just be consistent
and always set ErrorType for invalid AST. This should only affect
things like implicit nodes.
2025-08-11 12:05:10 +01:00
Hamish Knight
9d9b4c90c6 [Sema] Sink Pattern invalidation into SyntacticElementTarget::markInvalid
Rather than handling this in the callers of `typeCheckExpression`,
handle it in the constraint system's invalidation logic. This also
ensures we set a type for sub-pattern nodes.
2025-08-11 12:05:10 +01:00
Hamish Knight
ce9028f816 [Sema] Set pattern on failure in typeCheckBinding
I don't think this currently affects anything, but match what we do
for the expression and update the pattern if type-checking the
initialization fails.
2025-08-11 12:05:10 +01:00
Hamish Knight
27e2514eff [CS] Better handle unsupported result builder elements for completion
Instead of failing, fall back to solving as a regular function body.

rdar://144303920
2025-08-11 11:19:14 +01:00
Hamish Knight
e0791bb38d [CS] Fix check in applyResultBuilderBodyTransform
If `matchResultBuilder` returns `nullopt` we should be bailing,
rather than continuing, which would attempt to solve with an empty
constraint system.
2025-08-11 11:19:14 +01:00
Hamish Knight
931289988e [CS] NFC: Remove an unused return value
`isBuildableIfChainRecursive` never returned anything other than `true`,
change it to just be a void call.
2025-08-11 11:19:14 +01:00
Hamish Knight
1e012fea05 [CS] Avoid bailing on result builder return for completion
Make sure we continue to solve the body normally rather than bailing
early.
2025-08-11 11:19:14 +01:00
Hamish Knight
acf6375d46 Introduce BindExtensionsForIDEInspectionRequest
This allows us to lazily bind extensions after mutating the AST,
ensuring we don't prematurely kick the building of lookup tables.
2025-08-10 23:49:03 +01:00
Allan Shortlidge
5e246174a9 Merge pull request #83607 from tshortli/allow-obsolete-in-unavailable-contexts
Sema: Rationalize availability checking in unavailable contexts
2025-08-08 13:00:10 -07:00
Pavel Yaskevich
4e445d1483 Merge pull request #83556 from xedin/rename-nonisolated-caller-to-nonsending
[AST] NFC: Rename function type isolation `NonisolatedCaller` to `Non…
2025-08-08 09:37:17 -07:00
Allan Shortlidge
4d41db3b5d Sema: Rationalize availability checking in unavailable contexts.
Correct several behaviors of availability checking in unavailable contexts that
were inconsistent with the checking model:

- Avoid diagnosing unintroduced and obsolted declarations in contexts that are
  unavailable in the same domain.
- Diagnose unavailability normally in type signature contexts.
2025-08-08 07:57:44 -07:00
Hamish Knight
5755fb293f Merge pull request #83585 from hamishknight/ext-info
Avoid dropping ExtInfo in `replaceParamErrorTypeByPlaceholder`
2025-08-08 09:53:12 +01:00
Gábor Horváth
35b5c817b2 Merge pull request #83520 from Xazax-hun/check-safety-function-types 2025-08-08 06:39:39 +01:00