Commit Graph

2525 Commits

Author SHA1 Message Date
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Alejandro Alonso
acbae0cf34 Merge pull request #79618 from Azoy/another-bug-another-dollar
[AST] Directly store GTPD in TypeValueExpr
2025-02-26 07:59:09 -08:00
Alejandro Alonso
15c32e117b Directly store GTPD in TypeValueExpr 2025-02-25 14:11:55 -08:00
Hamish Knight
c69590fbdd [CS] Clean up pack expansion environment handling a little
- Track environments for `PackExpansionExpr` directly
instead of using a locator.
- Split up the querying and creation of the environment
such that the mismatch logic can be done directly in
CSSimplify instead of duplicating it.
- Just store the environment directly instead of
the shape and UUID.
2025-02-20 21:31:46 +00:00
Pavel Yaskevich
484e0a7437 [ConstraintSystem] Sendable-to-Any: Allow conversion when in inout positions
It should be possible to pass values with `any Sendable` as arguments
to `inout` parameters that expect `Any`. This is pretty much the same
as an l-value conversion.

Resolves: https://github.com/swiftlang/swift/issues/79361
Resolves: rdar://144794132
2025-02-13 17:03:00 -08:00
Rintaro Ishizaki
73164a0ffd Merge pull request #79353 from rintaro/astgen-magic-ident-literal
[ASTGen] Generate MagicIdentifierLiteralExpr
2025-02-13 06:25:09 -08:00
Rintaro Ishizaki
563ddc47e2 [AST] Eliminate 'SYNTAX_KIND' from MagicIdentifierKinds.def
Nothing is using it.
2025-02-12 23:19:34 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Slava Pestov
17d8c820dc Merge pull request #79220 from slavapestov/fix-rdar143950572
AST: Source range of FuncDecl/ConstructorDecl should include the thrown type
2025-02-10 13:49:37 -05:00
Slava Pestov
92d8bf715f Sema: Remove unused variable 2025-02-10 09:17:40 -05:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Doug Gregor
84ed66f3be Ensure that distributed functions with typed throws can be called from outside
When calling a distributed function for an actor that might not be local,
the call can throw due to the distributed actor system producing an
error. The function might, independently, also throw. When the
function uses typed throws, we incorrectly treated the call is if it
would always throw the error type specified by the function. This
leads to incorrectly accepting invalid code, and compiler crashes in
SILGen.

The change here is to always mark calls to distributed functions
outside the actor as "implicitly throwing", which makes sure that we
treat the call sites as throwing 'any Error'. The actual handling of
the typed throw (from the local function) and the untyped throw (from
the distributed actor system) occurs in thunk generation in SILGen,
and was already handled correctly.

Fixes rdar://144093249, and undoes the ban introduced by rdar://136467528
2025-02-04 16:06:51 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Slava Pestov
5cbe8cbf56 Sema: Handle CGFloat <-> Double conversion in getOptionalEvaluationDepth() 2025-01-27 17:28:20 -05:00
Slava Pestov
0c2887db5b Sema: Simplify CSApply for Double<->CGFloat conversion 2025-01-27 16:42:03 -05:00
Anthony Latsis
87cf1179ff [NFC] Sema: Add Solution::getCalleeOverloadChoice 2025-01-16 02:35:26 +00:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Doug Gregor
8bb5bbedbc Implement an unsafe expression to cover uses of unsafe constructs
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:

    10 |   func sum() -> Int {
    11 |     withUnsafeBufferPointer { buffer in
    12 |       let value = buffer[0]
       |                   |     `- note: reference to unsafe subscript 'subscript(_:)'
       |                   |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
       |                   `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
    13 |       tryWithP(X())
    14 |       return fastAdd(buffer.baseAddress, buffer.count)

These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.

This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
2025-01-10 10:39:14 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Slava Pestov
c12e0a1e8f Merge pull request #78470 from slavapestov/fix-rdar141961300
Sema: Fix local property wrappers on constructor
2025-01-08 21:33:12 -05:00
Slava Pestov
cc2048764a Sema: Clean up local property wrapper bookkeeping 2025-01-08 14:31:12 -05:00
Alejandro Alonso
61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00
Pavel Yaskevich
8f7e71aa97 Merge pull request #78487 from xedin/Sendable-to-Any-for-lvalues
[CSApply] Sendable-to-Any: Add support for l-value to l-value and inout unsafe casts
2025-01-08 09:57:02 -08:00
Pavel Yaskevich
0a0a34c853 [CSApply] Add support for l-value to l-value and inout unsafe casts
`any Sendable` -> `Any` in generic argument positions should be
supported for l-value and inout types as well otherwise it won't
be possible to call setters and mutating methods.
2025-01-07 17:21:33 -08:00
Pavel Yaskevich
79f6b07961 [CSApply] Mark self parameter as inout when base/self match on deep equality
If type equality check fails we need to check whether the types
are the same with deep equality restriction since `any Sendable`
to `Any` conversion is now supported in generic argument positions
of @preconcurrency declarations. i.e. referencing a member on
`[any Sendable]` if member declared in an extension that expects
`Element` to be equal to `Any`.
2025-01-07 10:55:04 -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
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
74f8960bd8 Sema: Remove OneWayExpr and Builtin.one_way 2024-12-21 00:42:13 -08:00
Anthony Latsis
b6def6ec71 Merge pull request #77892 from AnthonyLatsis/magnolia-grandiflora
Sema: Subscript called with opened existential cannot produce lvalue if result is type-erased
2024-12-18 12:25:45 +00:00
Anthony Latsis
6612c9cf89 Sema: Subscript called with opened existential cannot produce lvalue if result is type-erased 2024-12-17 23:03:38 +00:00
Pavel Yaskevich
a2f711cf8e [ConstraintSystem] Make any Sendable -> Any behave the same in all language modes 2024-12-16 13:57:33 -08:00
Pavel Yaskevich
5e08f7e257 [CSApply/SILGen] Implement any Sendable to Any erasure for generic arguments
In non-strict concurrency mode when `@preconcurrency` declarations
are involved `any Sendable` should be treated as `Any` in generic
argument positions to support passing types that (partially) adopted
concurrency annotations to types that haven't yet done so.
2024-12-11 17:19:14 -08:00
Slava Pestov
d6b08c3c6d Merge pull request #77997 from slavapestov/csapply-astcontext
Sema: Stash the ASTContext in the ExprRewriter
2024-12-06 04:59:48 -05:00
Slava Pestov
8b3e219e37 Sema: Stash the ASTContext in the ExprRewriter 2024-12-05 18:41:31 -05:00
Hamish Knight
48dc186269 [CS] Correctly handle compound-applied functions with property wrappers
Avoid wrapping parameters in the function reference
for compound applies, and make sure we consult
the parameter label in the compound name if it's
present to determine whether to match using the
projected value or not. This matches the existing
logic in `unwrapPropertyWrapperParameterTypes`.
2024-12-05 15:55:20 +00:00
Hamish Knight
0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Pavel Yaskevich
1f7b76edd3 Merge pull request #77816 from xedin/fix-property-wrapper-projected-value-applies
[CSApply] Avoid shortcutting argument conversion when parameter has a…
2024-12-02 13:52:30 -08:00
Anton Korobeynikov
8e53ccd671 [AutoDiff] Peel off @sendable implicit conversion when checking for unsupported differentiable function conversion (#77869) 2024-12-02 10:29:37 -08:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Pavel Yaskevich
be1c9ad3eb [CSApply] CurryThunks: Add an assert to make sure that all applied property wrappers are used 2024-11-22 15:04:20 -08:00
Pavel Yaskevich
44908acd75 [CSApply] Avoid shortcutting argument conversion when parameter has an external property wrapper
The check to see whether argument matches the parameter exactly
causes two problems: prevents projected value initialized injection;
and, if there are multiple parameters with property wrappers,
would apply incorrect wrapper to other locations because the wrapper
application index wasn't incremented.

Resolves: rdar://140282980
2024-11-22 14:02:06 -08:00
Hamish Knight
68648f74ef [CS] Use adjusted type for single curry thunks
This matches the double curry thunk logic and
ensures that the resulting autoclosure matches the
expected type of the reference, avoiding mismatches
with parent expressions.

rdar://140212823
2024-11-21 12:14:00 +00:00
Hamish Knight
683c7ceb31 [CS] Simplify opened types earlier in buildMemberRef
Doesn't seem to be any reason not to do this
up-front, cleans up the code a little. Should be
NFC.
2024-11-21 12:13:59 +00:00
Slava Pestov
06b4953b85 Sema: Remove a usage of QueryTypeSubstitutionMap 2024-11-18 11:40:39 -05:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Hamish Knight
d8ec851c93 [Sema] NFC: Address review feedback on #77537 2024-11-12 18:35:17 +00:00
Hamish Knight
eef4716731 [Completion] Avoid doing extra type-checking in CSApply
Avoid type-checking local decls and macros, the
type-checking here should instead be handled by
TypeCheckASTNodeAtLocRequest.
2024-11-11 19:34:21 +00:00
Hamish Knight
fab09c50a0 Merge pull request #77479 from hamishknight/macro-misc-diag-fixes
[Sema] A couple of fixes for MiscDiagnostics on macro expansions
2024-11-11 19:27:58 +00:00
Hamish Knight
9c3b8a6256 [CS] Delay macro expansion until end of CSApply
Attempting to expand macros in the middle of
CSApply can result in attempting to run
MiscDiagnostics within a closure that hasn't yet
had the solution applied to the AST, which can
crash the implicit-self diagnostic logic. Move
the expansion to the end of CSApply such that
expansions are type-checked along with local
decls, ensuring it's run after the solution has
been applied to the AST.

rdar://138997009
2024-11-09 00:24:53 +00:00