Commit Graph

18474 Commits

Author SHA1 Message Date
Slava Pestov
59bdf6630c Sema: Move tuple conformance diagnostic to TypeCheckDeclPrimary.cpp 2023-08-09 17:42:25 -04:00
Hamish Knight
35a98f3828 [ASTGen] Allow querying of enabled features
For now this is using C interop, we ought to be
using C++ interop, but that's a much bigger
change.
2023-08-09 19:35:50 +01:00
Artem Chikin
0c6f212cd5 [Dependency Scanning] Add Clang modules from scan-deps queries to the set of
"already seen" modules, to pass down to subsequent queries.
2023-08-09 09:16:46 -07:00
swift-ci
d614d29c36 Merge pull request #67666 from ahoppen/ahoppen/kill-syntax-support
[AST] Remove gyb_syntax_support
2023-08-08 10:38:30 -07:00
Hamish Knight
1e3dd5c50c [AST] Improve source range info for TapExpr
Previously we would only base the start loc on the
`SubExpr`, but that isn't set until CSApply. Change
it to take both `SubExpr` and `Body`'s source range
into account.

Also tighten up the invariant that a TapExpr must
be created with a non-null BraceStmt.
2023-08-08 18:08:51 +01:00
Allan Shortlidge
cf5888a149 NFC: Refactor conveniences for filtering out unavailable decls.
Introduce `AvailableDuringLoweringDeclFilter` which can be composed with
`OptionalTransformRange` to implement iterators that filter out unavailable
decls.
2023-08-07 18:59:49 -07:00
Allan Shortlidge
774105bba1 NFC: Fix some documentation warnings. 2023-08-07 16:19:01 -07:00
Egor Zhdan
6261ee2bb5 Merge pull request #67772 from apple/egorzhdan/cxx-vector-proto
[cxx-interop] Add `CxxVector` protocol
2023-08-07 19:25:57 +01:00
Egor Zhdan
4acf9c8cf4 [cxx-interop] Add CxxVector protocol
This makes it possible to initialize `std::vector` from a Swift Sequence. This also conforms C++ vectors to `ExpressibleByArrayLiteral`, making it possible, for instance, to pass a Swift array to a C++ function that takes a vector of strings as a parameter.

rdar://104826995
2023-08-07 17:12:12 +01:00
Allan Shortlidge
cb7982d8d5 Merge pull request #67761 from tshortli/ast-unavailable-decl-queries
NFC: Hoist queries for unavailable decl optimizations into the AST library
2023-08-06 10:01:27 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Doug Gregor
300d04a2d4 Merge pull request #67642 from DougGregor/lazy-type-refinement-context
Eliminate Observable circular reference errors via lazier TypeRefinementContext building
2023-08-03 12:47:19 -07:00
Anton Korobeynikov
03334a8f92 [AutoDiff] Generalize handling of semantic result parameters (#67230)
Introduce the notion of "semantic result parameter". Handle differentiation of inouts via semantic result parameter abstraction. Do not consider non-wrt semantic result parameters as semantic results

Fixes #67174
2023-08-03 09:33:11 -07:00
Alejandro Alonso
f840191e14 Emit call to old initialization function for older OSes
Add test

Update raw_layout.swift

Update raw_layout.swift
2023-08-03 09:30:37 -07:00
swift-ci
bb6df83b63 Merge pull request #67701 from hamishknight/small-fixes
A couple of small fixes
2023-08-03 08:26:58 -07:00
Alex Lorenz
c4d6515d99 Merge pull request #67668 from hyp/eng/reverse-interop-simd-nested-fixes
[interop][SwiftToCxx] simd and nested type fixes
2023-08-03 06:36:16 -07:00
Hamish Knight
bd6f387b3e [AST] Correctly set LAST_EXPR 2023-08-03 13:00:12 +01:00
Doug Gregor
37959de29e Establish type refinement contexts for pattern binding decls directly
The type refinement context builder had a bunch of logic to try to
model type refinement contexts for the first variable declaration that
shows up within a pattern binding declaration. Instead, model this
more syntactically by creating a type refinement context for the
pattern binding declaration itself. This both addresses a regression
in the handling of `if #available` within a closure that's part of an
initializer, and fixes a bug in the same area where similar code has
explicit availability annotations.
2023-08-02 15:07:09 -07:00
Doug Gregor
3079f3d074 [Type refinement context] Lazily expand TRCs for pattern bindings
Eager expansion of type refinement contexts (TRCs) for variables
within pattern binding declarations is causing cyclic references in
some places involving macros. Make this expansion lazy, triggered by
walking into these pattern binding declarations as part of (e.g.)
availability queries.

Another step toward fixing the cyclic references in rdar://112079160.
2023-08-02 15:07:07 -07:00
Alex Lorenz
97c25ae854 [interop][SwiftToCxx] nested types are not yet supported so do not emit references to them 2023-08-02 13:03:05 -07:00
Hamish Knight
63cc9260c1 Merge pull request #67563 from hamishknight/complete
[CodeComplete] Properly handle `if`/`switch` expressions
2023-08-02 09:56:46 +01:00
Konrad `ktoso` Malawski
95920b2570 [Concurrency] Fix init task group with flags availability
resolves rdar://112469076
2023-08-02 12:02:27 +09:00
Alex Hoppen
ef8e4ac0f3 [AST] Remove gyb_syntax_support
We are no longer using these Python files to generate anything in SwiftSyntax. We can just remove them and instead commit the generated `.def` files.
2023-08-01 17:20:14 -07:00
Hamish Knight
bf3c807c27 [Sema] Introduce PreCheckFunctionBodyRequest
Split out the part of TypeCheckFunctionBodyRequest
that inserts and removes implicit returns.
2023-08-01 15:21:29 +01:00
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
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
swift-ci
617b25ac80 Merge pull request #67567 from nate-chandler/rdar112792831-2
[IRGen] alloc_stack may allocate pack metadata.
2023-07-27 18:32:25 -07:00
Allan Shortlidge
1381d9a7b2 Merge pull request #67575 from tshortli/fix-warnings
NFC: Fix warnings
2023-07-27 16:52:03 -07:00
Nate Chandler
471c9789c7 [AST] NFC: Refactor pack recursive properties.
Eliminated HasConcretePack and added HasPack and HasPackArchetype.
Renamed the old `hasPack` to `hasAnyPack`; as before, it means that the
type has a parameter pack, a pack, or a pack archetype.
2023-07-27 13:18:14 -07:00
Allan Shortlidge
f9a93a55d7 NFC: Fix duplicate definition of macro warnings.
Centralize the `SWIFT_{BEGIN/END}_NULLABILITY_ANNOTATIONS` definitions in a new
Nullability.h header to share.
2023-07-27 13:02:22 -07: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
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
Egor Zhdan
276a232ea8 Merge pull request #67536 from apple/egorzhdan/unsafe-cxx-mutable-input-iterator
[cxx-interop] Add `UnsafeCxxMutableInputIterator` protocol
2023-07-26 22:15:57 +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
Egor Zhdan
8d7d0efe13 [cxx-interop] Add UnsafeCxxMutableInputIterator protocol
This is an inheritor of the existing `UnsafeCxxInputIterator` protocol, with the only difference being the ability to mutate `var pointee` via a non-const `operator*()`.

This is needed to support mutable subscripts for `std::map` via `CxxDictionary`.

rdar://105399019
2023-07-26 18:20:49 +01:00
Allan Shortlidge
86265881c3 Merge pull request #67528 from tshortli/revert-66930
Sema: Resume diagnosing `@backDeployed` on functions with opaque result types as errors
2023-07-26 09:15:50 -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
Allan Shortlidge
e3453ca32a Revert "Sema: temporarily downgrade backdeployed_opaque_result_not_supported to a warning"
This reverts commit 0a3dadff90.
2023-07-25 21:13:31 -07:00
Doug Gregor
a0d52344bb Merge pull request #67513 from DougGregor/freestanding-macros-step-into-the-light 2023-07-25 20:44:29 -07:00
Steven Wu
b9fef33891 Merge pull request #67263 from cachemeifyoucan/eng/PR-explicit-module-interface-check
[ExplicitModule] Allow typecheck-module-from-interface using explicit module
2023-07-25 16:10:48 -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
Ben Barham
18cb5f4f3d [Diagnostics] Update in_macro_expansion note for attached macros
Use the attached atttribute's location as the location of the macro,
rather than the location of the declaration it's attached to. Also add
the kind and name of that declaration to the note itself.
2023-07-25 16:03:52 -07:00
Doug Gregor
6ac69d8c3c Remove findMacroForCustomAttr in favor of namelookup::lookupMacros
The former was effectively a copy of the latter.
2023-07-25 14:16:50 -07:00
Doug Gregor
f0f74e6c5e [Macros] Don't allow types to shadow freestanding macros.
When performing name lookup for freestanding macros (e.g., after the
`#`), don't allow types to shadow macros from imported libraries.

Fixes rdar://110429368.
2023-07-25 11:34:25 -07:00
Slava Pestov
f07495dd64 AST: Add TypePosition::Shape 2023-07-25 02:47:46 -04:00
Slava Pestov
747b060389 RequirementMachine: Correct desugaring of same-type requirements with pack expansion on both sides 2023-07-25 02:47:45 -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
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