Commit Graph

903 Commits

Author SHA1 Message Date
Hamish Knight
46df852610 [Sema] Reject placeholders in type resolution for param and result types
Not all clients can properly handle the presence of placeholders in
interface types and it doesn't seem worth the complexity for the 
type replacement diagnostic.
2025-09-19 14:22:39 +01:00
Hamish Knight
aa9aa58cea [Sema] Handle PlaceholderTypes in associated type inference
Avoid attempting to infer an associatedtype as a type that contains
placeholders.
2025-09-17 20:51:06 +01:00
Hamish Knight
d1b8084bc1 [Sema] Avoid resolving placeholders for protocol requirement params
We can't ever have default arguments in protocols anyway.
2025-09-17 20:51:06 +01:00
Hamish Knight
8102e39f39 [CS] Record fix when encountering decl reference with placeholder type
We allow placeholder types in interface types in certain cases to allow
better recovery since we can suggest the inferred type as a replacement.
When referencing those decls though we need to make sure we record a fix
since we cannot form a valid solution with them.
2025-09-17 20:51:06 +01:00
Hamish Knight
ab64e53b0c [Sema] Only resolve PlaceholderType result for FuncDecl with body
We allow resolving PlaceholderType here to allow MiscDiagnostics to
suggest replacing it with the inferred result type, but we won't run
that logic for non-FuncDecls and FuncDecls without bodies. Make sure
we reject placeholders in those cases.
2025-09-17 20:41:20 +01:00
Hamish Knight
78ea361257 [AST] Override getLocFromSource for ParamDecl
Ensure we can still produce a source location even if there's no name
loc, which is the case for e.g enum associated types.
2025-09-17 20:41:20 +01:00
Hamish Knight
63d63d8c60 [CS] Bail from conjunction for non-zero SK_Hole
Previously we would only do this for `SK_Fix`, do the same for `SK_Hole`
since otherwise the score clearing logic for the conjunction could
result in losing the hole score.
2025-09-15 21:43:58 +01:00
Hamish Knight
b7519fabe6 [CS] Add IgnoreInvalidASTNode fix for invalid generic argument
Make sure we record a fix here to ensure we don't try to do CSApply
with holes.
2025-09-15 11:48:56 +01:00
Hamish Knight
6761d8474d Merge pull request #84273 from hamishknight/the-whole-hole
[CS] Avoid forming DependentMemberType with hole base in `InferableTypeOpener`
2025-09-15 09:33:34 +01:00
Hamish Knight
6de09e1956 [test] Add some more known crashers 2025-09-14 10:35:53 +01:00
Hamish Knight
0f7490aae1 [CS] Avoid forming DependentMemberType with hole base in InferableTypeOpener
Type substitution can form DependentMemberTypes with error base types,
avoid forming a DependentMemberType with a hole base in
`InferableTypeOpener`, instead form a hole that covers the entire type.
2025-09-14 10:09:39 +01:00
Rintaro Ishizaki
31b5d55f33 Merge pull request #84128 from rintaro/parse-attr-lparen-space-rdar147785544
[Parse] Change whitespace rule between attribute name and '(' in Swift 6
2025-09-12 18:19:53 -07:00
Hamish Knight
c84d2abb05 [AST] Allow storing original expression in ErrorTypeRepr
This is useful for ArrowExpr when the sub-expressions aren't valid
TypeExprs. Rather than throwing away the AST, attach it to the
ErrorTypeRepr to ensure we can still type-check it. This ensures
semantic functionality still works correctly, and fixes a crash where
we'd stop visiting an invalid binding pattern, losing track of the
nested VarDecl.
2025-09-11 13:21:03 +01:00
John McCall
e5b6a88c5e Merge pull request #84181 from rjmccall/isolation-fixes
Isolation fixes for closures and defer bodies
2025-09-10 08:39:09 -04:00
Hamish Knight
872176bdd1 Merge pull request #84149 from hamishknight/case-and-pat
A few pattern cleanups + fixes
2025-09-10 09:36:22 +01:00
Rintaro Ishizaki
b119407966 [Parse] Change whitespace rule between attribute name and '(' in Swift 6
In Swift 6 and later, whitespace is no longer permitted between an
attribute name and the opening parenthesis. Update the parser so that
in Swift 6+, a `(` without preceding whitespace is always treated as
the start of the argument list, while a '(' with preceding whitespace is
considered the start of the argument list _only when_ it is unambiguous.

This change makes the following closure be parsed correctly:

  { @MainActor (arg: Int) in ... }

rdar://147785544
2025-09-09 16:44:29 -07:00
Slava Pestov
68be47f166 Sema: Re-organize some logic in getTypeOfMemberReference() 2025-09-09 18:58:10 -04:00
Slava Pestov
13b4b03aca Sema: Fix crash in IgnoreAssignmentDestinationType::diagnoseForAmbiguity() 2025-09-09 18:58:10 -04:00
John McCall
3088b85c2c Don't crash if there's a request cycle with DefaultArgumentExprRequest. 2025-09-09 14:26:57 -04:00
Hamish Knight
9db82cbe62 [AST] Avoid walking a few more expressions in WalkToVarDecls
Avoid walking TapExprs, SingleValueStmtExprs, and key paths. The latter
is important since they can contain invalid VarDecls that will no
longer be visited by the ASTWalker after key path resolution, so we
don't want to create case body vars for them.
2025-09-09 13:48:40 +01:00
Hamish Knight
7fb532e4e6 Merge pull request #83776 from hamishknight/the-diags-never-stop-no
[Diags] Allow multiple in-flight diagnostics
2025-09-03 19:59:44 +01:00
eeckstein
50b5ecf042 Merge pull request #84013 from eeckstein/canonical-substitution-maps
SIL: only use canonical substitution maps in SIL
2025-08-30 20:30:07 +02:00
Erik Eckstein
6df033b298 SIL: only use canonical substitution maps in SIL
* When constructing instructions which have substitution maps: initialize those with the canonical SubstitutionMap
* Also initialize SILFunction::ForwardingSubMap with the canonical one

Non-canonical substitution maps may prevent generic specializations.
This fixes a problem in Embedded Swift where an error is given because a function cannot be specialized, although it should.

https://github.com/swiftlang/swift/issues/83895
rdar://159065157
2025-08-29 22:31:04 +02:00
Hamish Knight
28772234bc [CS] Allow contextual types with errors
Previously we would skip type-checking the result expression of a
`return` or the initialization expression of a binding if the contextual
type had an error, but that misses out on useful diagnostics and
prevents code completion and cursor info from working. Change the logic
such that we open ErrorTypes as holes and continue to type-check.
2025-08-29 15:04:20 +01:00
Hamish Knight
1b0eed22be [CS] Better propagate holes from contextual types
Eagerly bind invalid type references to holes and propagate contextual
type holes in `repairFailures`. This avoids some unnecessary diagnostics
in cases where we have an invalid contextual type.
2025-08-29 15:04:20 +01:00
Hamish Knight
a309fc0ac9 Merge pull request #83992 from hamishknight/tweak-assert 2025-08-29 06:08:57 +01:00
Slava Pestov
4f6d7f40ec Merge pull request #83986 from slavapestov/fix-rdar158774099
AST: Remove old hack that appears to be obsolete and revert a revert of another fix
2025-08-28 23:59:46 -04:00
Hamish Knight
b90494b9ec Merge pull request #83985 from hamishknight/null-ext
[ASTDumper] Check null for `getExtendedTypeRepr`
2025-08-29 02:34:18 +01:00
Hamish Knight
627f41ccbc [CS] Fix an overly strict assert
`matchExistentialTypes` can handle existential metatypes, fix the
assert to handle that.
2025-08-29 00:17:14 +01:00
Slava Pestov
672135b053 AST: Remove old hack that appears to be obsolete
The FIXME was originally introduced in 2017 by commit c0805a2bc8.

Good riddance!
2025-08-28 16:51:49 -04:00
Hamish Knight
dfc940f82d [ASTDumper] Check null for getExtendedTypeRepr
This can be null for `extension {}`.
2025-08-28 20:46:16 +01:00
Hamish Knight
79e8a6cb3c [Sema] Avoid marking TypeRepr invalid with SilenceErrors
Pattern resolution currently invokes type resolution with this flag
since it's trying to see if it can treat a given expression as a
TypeRepr for e.g an enum pattern. Make sure we don't `setInvalid` on
such TypeRepr nodes since that will avoid diagnosing in cases where
the node also then gets treated as a TypeRepr for an ExprPattern,
where we actually want the diagnostic emitted.
2025-08-28 15:31:48 +01:00
Hamish Knight
0c16c00bb4 [Sema] Resolve interface type in ExtendedTypeRequest
Resolving only a structural type meant we weren't checking generic
constraints, allowing invalid extensions to get past the type-checker.
Change to resolve an interface type.
2025-08-24 11:49:14 +01:00
Hamish Knight
0c29284098 [test] Add some more known crashers 2025-08-22 00:54:18 +01: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
Hamish Knight
45065f3069 [Diags] Allow multiple in-flight diagnostics
Lift the limitation of a single active diagnostic, which was a pretty
easy-to-hit footgun. We now maintain an array of active in-flight
diagnostics, which gets flushed once all them have ended.
2025-08-17 11:48:21 +01: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
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
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
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
Pavel Yaskevich
3879a47b52 [CSSyntacticElement] Remove an assert that is too strict
`return` statement withot an expression automatically gets an
implicit `()` which is allowed to be converted to types like
`()?` and `Any` or `Any?`. Let's remove a too strict assertion
that expected a contextual type to always be `()?` even
through in reality any type that `()` is convertible to is valid.

Resolves: rdar://152553143
2025-08-04 00:17:26 -07:00
Hamish Knight
fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Slava Pestov
5866d8a36a Sema: Fix crash with invalid reference to macro 2025-07-24 12:55:47 -04:00
Pavel Yaskevich
3b06d87e90 Merge pull request #83179 from xedin/rdar-128109889
[ASTVerifier] Allow `inout` and `Array` to pointer conversion in vari…
2025-07-23 07:48:58 -07:00
Hamish Knight
994b9d197b [test] Add some more known crashers 2025-07-21 10:47:59 +01:00
Slava Pestov
b70f8a82b1 Sema: Improve the infinite opaque return type check
Now look through other opaque return types that appear in the
underlying type. This catches various forms of recursion that
otherwise would cause a SILGen or SILOptimizer crash.

- Fixes rdar://82992151.
2025-07-18 20:03:03 -04:00
Pavel Yaskevich
b5aa8173ce [ASTVerifier] Allow inout and Array to pointer conversion in variadic parameter positions
Fixes a verifier crash that prevented use of valid conversions.

Resolves: https://github.com/apple/swift/issues/73454
Resolves: rdar://128109889
2025-07-18 11:35:21 -07:00
Slava Pestov
ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Hamish Knight
818979fed8 Merge pull request #83034 from hamishknight/origami
[Sema] Avoid folding sequences multiple times
2025-07-15 09:14:55 +01:00
Hamish Knight
95f1b07e87 [Sema] Remove completion assert in foldSequence for now
Turns out we can also hit this case for some pattern type-checking
cases. I'll fix those in a follow-up and reinstate the assertion.
2025-07-14 18:50:42 +01:00