Commit Graph

1544 Commits

Author SHA1 Message Date
Tim Kientzle
4c0b58096e Make _InlineArray subject to the same optimizations as InlineArray 2025-10-10 14:06:14 -07:00
Hamish Knight
2c0ea134a9 [Sema] Remove some hasError checks for typeCheckPattern
These shouldn't be necessary anymore, we should be able to handle
ErrorType patterns.
2025-09-28 15:13:55 +01:00
Slava Pestov
9dea72579a Sema: Record ASTNode type changes in PreparedOverload
Also, move some methods from ConstraintSystem.h to ConstraintSystem.cpp.
2025-09-18 14:54:16 -04:00
Slava Pestov
a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Hamish Knight
deab5f7970 Merge pull request #84280 from hamishknight/csapply-cleanup
Reapply: [Sema] Remove some unreachable code from CSApply
2025-09-18 14:25:51 +01:00
Hamish Knight
9f5a754b77 [Sema] Ban placeholders in typed throws
This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
2025-09-17 20:41:20 +01:00
Hamish Knight
a7c0460877 [CS] Record IgnoreInvalidASTNode for invalid key path component
And ensure we don't end up with invalid key paths in CSApply.
2025-09-17 16:11:53 +01:00
Hamish Knight
be1f82e36b [CS] Avoid emitting duplicate note for generic argument diagnostic
Since we can run CSGen multiple times, we need to guard the emission
of the note on whether the TypeRepr was already marked invalid (i.e
whether we already emitted a diagnostic for it).
2025-09-15 11:48:56 +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
ef7d69631b [CS] Avoid unnecessary type variables when opening ErrorTypes
Produce the holes directly.
2025-08-30 16:05:01 +01: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
2e0be5afd7 [CS] Open generic requirements for types with unbound + placeholder types
- Introduce a generic requirements opening function for type resolution,
  which is used by the constraint system in cases where we need to
  impose requirements on opened type variables.
- Refactor `replaceInferableTypesWithTypeVars` to use this function
  when opening generic types that contain either placeholder or unbound
  generic types.

Together these changes ensure that we don't drop generic requirements
when an unbound generic or placeholder type is used as a generic
argument.
2025-08-26 12:16:54 +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
Slava Pestov
44bd5be56f Merge pull request #82976 from slavapestov/prepared-overloads-part-2
Prepared overloads, part 2
2025-07-11 19:10:15 -04:00
Slava Pestov
9a8f3baa06 Sema: Add room for a PreparedOverload to BindOverload constraint 2025-07-10 19:53:19 -04:00
Slava Pestov
f7a552385c Sema: PreparedOverload => PreparedOverloadBuilder 2025-07-10 19:53:18 -04:00
Doug Gregor
84e202eb02 Merge pull request #82954 from DougGregor/strict-memory-safety-codable-synthesis
[Strict memory safety] Eliminate spurious warnings with synthesized Codable
2025-07-10 14:07:27 -07:00
Doug Gregor
1142fa3bdd [Strict memory safety] Eliminate spurious warnings with synthesized Codable
When synthesizing code for Codable conformances involving unsafe types,
make sure to wrap the resulting expressions in "unsafe" when strict memory safety is enabled.

Tweak the warning-emission logic to suppress warnings about spurious
"unsafe" expressions when the compiler generated the "unsafe" itself,
so we don't spam the developer with warnings they can't fix. Also make
the checking for other suppression considerations safe when there are
no source locations, eliminating a potential assertion.

Fixes rdar://153665692.
2025-07-10 09:03:04 -07:00
Doug Gregor
3542b1df0f Merge pull request #82938 from DougGregor/unsafe-for-in-fixes 2025-07-09 23:16:52 -07:00
Doug Gregor
35628cb503 [Strict memory safety] Fix "unsafe" checking for the for..in loop
The `$generator` variable we create for the async for..in loop is
`nonisolated(unsafe)`, so ensure that we generate an `unsafe`
expression when we use it. This uncovered some inconsistencies in how
we do `unsafe` checking for for..in loops, so fix those.

Fixes rdar://154775389.
2025-07-09 16:19:14 -07:00
Slava Pestov
751edee921 Sema: Rework PreparedOverload to store a list of changes 2025-07-09 15:00:10 -04:00
Slava Pestov
2a0b11a22e Sema: Collect property wrappers in PreparedOverload 2025-07-09 15:00:03 -04:00
Hamish Knight
5df9933fad [AST] Enforce non-null type for value GenericTypeParamType
Make sure we have a value type for a value generic parameter.
2025-07-02 14:46:55 +01:00
Hamish Knight
3daae5955e [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 14:46:55 +01:00
Pavel Yaskevich
eee40b4ecc [CSGen] Make collection subscript result type inference more principled
Infer result type of a subscript with Array or Dictionary base type
if argument type matches the key type exactly or it's a supported
literal type.

This helps to maintain the existing behavior without having to resort
to "favored type" computation.
2025-06-27 23:43:12 -07:00
Pavel Yaskevich
286f975c29 Merge pull request #82320 from xedin/hide-solver-hacks-behind-a-flag
[ConstraintSystem] Guard all the performance hacks with a flag
2025-06-20 00:12:16 -07:00
Hamish Knight
c6ec3156f7 [CS] Distinguish locators for generic args in addSpecializationConstraint
Make sure we give each argument a different locator to ensure we
can correctly record any opened types.

rdar://153674889
2025-06-18 12:19:12 +01:00
Pavel Yaskevich
fc573b6612 [ConstraintSystem] Guard all the performance hacks with a flag
Package the flag into `performanceHacksEnabled()` method on
`ConstraintSystem` and start using it to wrap all of the hacks
in constraint generator and the solver.
2025-06-17 13:53:05 -07:00
Hamish Knight
71d20b7635 [CS] NFC: Remove FreeTypeVariableBinding::UnresolvedType
This is now unused.
2025-06-12 12:11:19 +01:00
Slava Pestov
0e1561f05a Sema: Change a couple of Identifier usages to DeclName instead 2025-05-30 14:43:48 -04:00
Alejandro Alonso
d5970d93b8 Check if we're a bound struct 2025-05-08 14:30:01 -07:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Alejandro Alonso
79a51dfcc1 Move resolving param type to CSApply 2025-04-14 15:33:08 -07:00
Alejandro Alonso
ae355007fc Store TypeRepr in TypeValueExpr 2025-04-14 15:33:08 -07:00
Alejandro Alonso
b3f3dd79cf Handle dynamically accessing the static member from type(of:) 2025-04-14 15:32:46 -07:00
Pavel Yaskevich
3906980f58 [AST] NFC: Add a convenient way to create implicit NonisolatedAttrs 2025-04-11 15:59:25 -07:00
Pavel Yaskevich
07ff063ae3 [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-11 15:59:25 -07:00
Pavel Yaskevich
4b8c8e7d72 [AST/Sema] Replace @execution(concurrent) with @concurrent 2025-04-11 12:08:29 -07:00
Allan Shortlidge
b97ec5bbe5 Sema: Improve MemberImportVisibility diags for for-in loops.
Ensure that source locations are attached to the implicit calls to
`makeIterator()` and `next()` for diagnostics.

Partially resolves rdar://144535697.
2025-04-05 09:47:56 -07:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Allan Shortlidge
5dc7a204cb Sema: Address -Wunused-but-set-variable warnings. 2025-03-28 12:33:40 -07:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Amritpan Kaur
724e3f9910 [Constraint System] Evaluable hashability during constraint generation. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
6af6374e39 [CSGen] Generate constraints for keypaths to methods. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
2583da94b2 [NFC] Generalize subscript index handling. 2025-03-19 08:53:18 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Amritpan Kaur
8f71f5c780 [NFC] Rename property to member to generalize
for both properties and method members.
2025-03-19 08:53:18 -07:00
Pavel Yaskevich
00af0eeb0f Merge pull request #79975 from xedin/execution-attr-on-closures
[Concurrency] Extend `@execution(...)` attribute support to closures
2025-03-13 09:25:19 -07:00
Pavel Yaskevich
570eedbdc7 [ConstraintSystem] Update closure inference to support @execution(...) attribute
- Update `ClosureEffectsRequest` to make sure that closure is
marked as `async` when `@execution(...)` attribute is present.

- Update `inferClosureType` to set isolation based on an explicit
`@execution(...)` attribute attached to a closure.
2025-03-12 18:08:53 -07:00