Commit Graph

24025 Commits

Author SHA1 Message Date
Joe Groff
16c59fa12c Merge pull request #67588 from jckarter/raw-layout-multi-file
Requestify raw layout "like" type resolution.
2023-07-31 08:38:49 -07:00
Hamish Knight
58a8a2ae9a Merge pull request #67591 from hamishknight/quieter
[CS] Avoid emitting invalid binding diagnostic in more cases
2023-07-29 01:45:35 +01:00
Joe Groff
56f2ae6b08 Requestify raw layout "like" type resolution.
This ensures it's resolved on demand even across files. rdar://112998213
2023-07-28 13:46:50 -07:00
Joshua Turcotti
2eade1d1b5 Merge pull request #67511 from JTurcotti/tweaks
[SendNonSendable] Assorted Bugfixes and Tweaks
2023-07-28 09:24:36 -07:00
Slava Pestov
518d7298e7 Merge pull request #67566 from slavapestov/referenced-generic-params
Sema: Fix two problems in checkReferencedGenericParams() analysis
2023-07-28 09:32:13 -04:00
Hamish Knight
2210ea6856 [CS] Avoid emitting invalid binding diagnostic in more cases
Also avoid emitting the diagnostic for an out of
place binding pattern if there's an existing fix
on a parent call expression, as that's the real
source of the failure.

rdar://113025351
2023-07-28 11:22:27 +01:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
Allan Shortlidge
7c93887c21 Merge pull request #67556 from tshortli/derived-codable-conformance-unavailable-enum-element
Sema: Avoid decoding unavailable enum elements in derived Codable conformances
2023-07-27 13:07:24 -07:00
Amritpan Kaur
9e4f23b7c2 [CSGen] Update Constraint Locator for KeyPathValue 2023-07-27 12:48:09 -07:00
Pavel Yaskevich
9b3980573f Merge pull request #67297 from amritpan/build-out-resolve-kp
[ConstraintSystem] Set up keypath expressions typechecking
2023-07-27 09:52:09 -07:00
Slava Pestov
3e436d316f Sema: Fix two problems in checkReferencedGenericParams() analysis
- Don't walk into the count type of a PackExpansionType, because
  when matching two PackExpansionTypes, the solver only introduces
  a shape constraint between the count types, which does not fix it
  to a concrete type.

- Similarly, don't walk into type alias substitutions, because
  only the desugared type is considered by the constraint solver.

This is mildly source breaking, in that before we let you declare
generic functions that could not be called.
2023-07-27 12:16:06 -04:00
Allan Shortlidge
7996c5b30c Sema: Avoid decoding unavailable enum elements in derived Codable conformances.
The compiler derived implementations of `Codable` conformances for enums did
not take enum element unavailability into account. This could result in
unavailable values being instantiated at runtime, leading to a general
violation of the invariant that unavailable code is unreachable at runtime.
This problem is possible because synthesized code is not type checked; had the
conformances been hand-written, they would have been rejected for referencing
unavailable declarations inside of available declarations.

This change specifically alters derivation for the following declarations:
- `Decodable.init(from:)`
- `Encodable.encode(to:)`
- `CodingKey.init(stringValue:)`

Resolves rdar://110098469
2023-07-26 22:48:25 -07:00
Amritpan Kaur
3140c12691 [CSSimplify] If keypath is malformed, do not attempt to 2023-07-26 20:32:30 -07:00
Amritpan Kaur
6296be7464 [CSSimplify] If bound type var is more optional
than a binding type var, attempt to match
types and solve.
2023-07-26 20:32:26 -07:00
Ben Barham
7e8a33097e Merge pull request #67488 from bnbarham/better-note-locations
[Diagnostics] Improve diagnostics involving macros
2023-07-26 17:48:02 -07:00
Michael Gottesman
8c82b6b7d9 Merge pull request #67546 from gottesmm/pr-9bcf05ac3fb12f2872cc63507f782c766eba18b7
[sema] Ban user created read/set accessor that produce noncopyable types
2023-07-26 16:44:29 -07:00
Hamish Knight
c415744f26 Merge pull request #67537 from hamishknight/loc-step 2023-07-26 22:16:53 +01:00
Michael Gottesman
2a1d9199a3 [sema] Ban user created read/set accessor that produce noncopyable types.
The reason why we are doing this is that this combination of read/set forces the
compiler to emit a copy if we want to emit a modify operation.

The reason why we are forced to emit such a copy is that:

1. _read provides a guaranteed value in memory
2. performing a modify requires an owned value in memory.

This together implies that the only way we can do this is to copy from the _read
into temporary memory. But we have a noncopyable type so we can't do this.

rdar://112915525
2023-07-26 12:53:43 -07:00
Joe Groff
705e317c3f Merge pull request #67425 from jckarter/raw-storage
[WIP] Raw storage and locks/atomics prototype
2023-07-26 08:49:02 -07:00
Hamish Knight
a64ba23d7b [CS] NFC: Store ContextualTypeInfo in SyntacticElementTarget
Move the contextual type locator onto
ContextualTypeInfo, and consolidate the separate
fields in SyntacticElementTarget into storing a
ContextualTypeInfo. This then lets us plumb down
the locator for the branch contextual type of an
if/switch expression from the initial constraint
generation, rather than introducing it later. This
should be NFC.
2023-07-26 16:46:54 +01:00
Amritpan Kaur
5fa54dfc4d [CSSimplify] Delay matchTypes for key path values
until they are directly bound.
2023-07-25 22:16:28 -07:00
Holly Borla
106f4349b1 Merge pull request #67524 from hborla/suppress-conformance-macro-error
[Macros] Suppress the conformance macro diagnostic in swiftinterfaces.
2023-07-25 20:42:56 -07:00
Holly Borla
e461c25fa5 [Macros] Suppress the conformance macro diagnostic in swiftinterfaces. 2023-07-25 17:15:09 -07:00
Ben Barham
9691060418 [Diagnostics] Add declaration name to macro_attached_to_invalid_decl
This could also use `%kind` for the declaration kind, but that ends up
being "extension of struct" instead of just "extension", which seems
slightly worse.
2023-07-25 16:03:52 -07:00
Slava Pestov
bf1894714b Merge pull request #67502 from slavapestov/rqm-shape-req-fixes
RequirementMachine: Fix some edge cases with shape requirements
2023-07-25 17:50:34 -04:00
Slava Pestov
f07495dd64 AST: Add TypePosition::Shape 2023-07-25 02:47:46 -04:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
Pavel Yaskevich
b8915fa39a [CSSimplify] Repair should ignore situations where assignment source or destination are a hole
If either source or destination type is a hole conversion should
just be ignored because there is no r-value or other mismatch that
could be diagnosed in this case.
2023-07-24 12:09:04 -07:00
Pavel Yaskevich
9e388b40e1 [CSSimplify] Check that raw type is not a hole before checking RawRepresentable conformance
Placeholder types just like type variables are set up to return
a conformance ref which, in this case, would mean that we'd produce
an invalid diagnostic.
2023-07-24 11:15:50 -07:00
Pavel Yaskevich
33a37b9516 Merge pull request #67377 from xedin/rdar-112090069
[CSSimplify] Extend same-shape detection to account for pack archetypes
2023-07-24 10:01:29 -07:00
Pavel Yaskevich
31d1c4c79f Merge pull request #67326 from xedin/rdar-110721928
[CSSimplify] Deplay member lookup until single-element tuple with pac…
2023-07-24 09:59:59 -07:00
Evan Wilde
669285fd17 Merge pull request #65534 from stephank/fix/cmake-3.25
build: fix accidental cmake expansions
2023-07-24 09:44:14 -07:00
Freddy Kellison-Linn
d13e997d07 [TypeCheckPattern] Attempt ExprPattern conversion before failing pattern coercion to optional 2023-07-23 12:04:38 -04:00
Holly Borla
a60b302754 [Macros] Diagnose invalid attached macros at the attribute location instead
of the declaration.
2023-07-21 16:31:10 -07:00
Pavel Yaskevich
eb86497493 [CSSimplify] Deplay member lookup until single-element tuple with pack expansion is sufficiently resolved
Such tuples should be treated specially because once pack expansion
is sufficiently resolved they'd get exploded and the resulting type
is what member lookup should use as a base.

Resolves: rdar://110721928
2023-07-21 13:10:34 -07:00
Pavel Yaskevich
11ee82de7b [CSBindings] Prefer conjunctions over closure variables without bindings
If a closure doesn't have a contextual type inferred yet it should
be delayed in favor of already resolved closure conjunction because
"resolving" such a closure early could miss result builder attribute
attached to a parameter the closure is passed to.

Partially resolves https://github.com/apple/swift/issues/67363
2023-07-21 09:46:09 -07:00
Pavel Yaskevich
dbb38f1bf3 Merge pull request #67435 from xedin/rdar-112029630
[CSRanking] Augment overload ranking to account for variadic generics
2023-07-21 09:44:01 -07:00
Pavel Yaskevich
5a5edcafc3 [CSSimplify] Extend same-shape detection to account for pack archetypes
`same-shape` mismatch detection logic shouldn't expect that types are
always packs because they could be either invalid (i.e. Void) or pack
archetypes too.

Resolves: rdar://112090069
2023-07-20 22:50:22 -07:00
Holly Borla
8091744296 Merge pull request #67428 from hborla/dependent-type-pack-syntax
[Type Resolution] Only allow `each` applied directly to a type parameter pack.
2023-07-20 20:12:32 -07:00
swift-ci
7741409f8e Merge pull request #67075 from beccadax/kinder-diagnostics
Improve DiagnosticEngine's handling of ValueDecl arguments
2023-07-20 18:26:14 -07:00
swift-ci
c3c84d3625 Merge pull request #67421 from JTurcotti/more-diags
[SendNonSendable] Improve diagnostics and fix bugs
2023-07-20 16:56:56 -07:00
Holly Borla
7b586d20cc [Type Resolution] Only allow each applied directly to a type parameter pack. 2023-07-20 15:29:53 -07:00
Becca Royal-Gordon
fe6753485f [NFC] Adopt new diagnostic features across Sema 2023-07-20 15:23:47 -07:00
Pavel Yaskevich
b98cd11f12 [CSRanking] Augment overload ranking to account for variadic generics
If one of the choices is variadic generic, let's use `matchCallArguments`
to find argument/parameter mappings and form pack expansions for arguments
when necessary.

Resolves: rdar://112029630
2023-07-20 10:15:08 -07:00
Pavel Yaskevich
59908eeb0d [CSGen] Suppress favoring in presence of non-disfavored variadic generic overloads
Since this type of early favoring checks number of arguments and matches
labels it would always favor non-variadic overloads which is incorrect.
2023-07-20 10:02:59 -07:00
Sophia Poirier
60c579c001 Merge pull request #67415 from sophiapoirier/remove-TupleType-isSingleUnlabeledPackExpansion
[ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple
2023-07-20 09:43:14 -07:00
Holly Borla
f76783d619 Merge pull request #67405 from hborla/enable-extension-macros
[Macros] Remove the `ExtensionMacros` experimental feature flag.
2023-07-19 17:59:21 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
Pavel Yaskevich
b6edb098cf Merge pull request #67294 from xedin/default-init-via-accessor-in-custom-initializers
[Sema/SIL] InitAccessors: Support default initialization of init accessor properties
2023-07-19 15:32:33 -07:00
Sophia Poirier
8173c721eb [ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple 2023-07-19 15:10:40 -07:00