Commit Graph

953 Commits

Author SHA1 Message Date
Pavel Yaskevich
438ee330f1 [ConstraintSystem] Add new conversion kind - ArrayToCPointer
It's `ArrayToPointer` conversion that has PointerToCPointer
semantics for (un-)signed integer element types.
2023-03-14 11:22:52 -07:00
Holly Borla
8012e45109 [Diagnostics] Diagnose pack element expressions containing a non-pack subexpression. 2023-03-05 00:11:54 -08:00
Andrew Trick
f1ff6958a3 Merge pull request #63825 from atrick/diagnose-implicit-raw-bitwise
Warn on implicit pointer conversion from nontrivial inout values.
2023-03-02 10:57:30 -08:00
Kavon Farvardin
cc0b668efb Merge pull request #63922 from kavon/standard-issue-neuralyzer
Implement the `forget` statement (as `_forget`)
2023-03-01 11:10:25 -08:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Andrew Trick
185e6fabd5 Add TypeBase::isArrayType helper API.
This is also needed in SIL diagnostics, not just Sema diagnostics,
because implicit Array conversion generates special SIL patterns.
2023-02-27 21:51:17 -08:00
Zoe Carver
5406f1aafe Merge pull request #63673 from zoecarver/fixits-for-common-swiftifications
[cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]".
2023-02-22 10:13:36 -08:00
zoecarver
38658a051f [cxx-interop] Fix test for linux; bail if we didn't load the overlay. 2023-02-21 10:52:57 -08:00
Luciano Almeida
22a18de1b1 [Sema] Improving integer literal as boolean diagnostic 2023-02-21 10:30:48 -03:00
zoecarver
1b0ee8e8de [cxx-interop] Fix two source locations; replace end with nil. 2023-02-20 14:57:51 -08:00
zoecarver
d19b587c35 [cxx-interop] Update based on review feedback. 2023-02-20 14:57:50 -08:00
zoecarver
5ac94a8a90 [cxx-interop] Completely overhaul diagnostics/notes for unsafe projections. 2023-02-20 14:57:50 -08:00
zoecarver
4e0860b0d2 [cxx-interp] Add fix-its for front(), back(), begin(), and end(). 2023-02-20 14:57:50 -08:00
zoecarver
9ce9310df5 [cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]".
Only applies to random access collections. The first of many fix-its like this :)
2023-02-20 14:57:50 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Holly Borla
e41cdfbdd4 Merge pull request #63341 from hborla/generalize-macro-expansion-expr
[Macros] Generalize `MacroExpansionExpr` and use it for both freestanding and attached macros.
2023-02-01 11:04:39 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Holly Borla
9b5cf1d2ff [Diagnostics] Remove the MacroMissingArguments constraint fix and its
associated failure diagnostic.

This constraint fix is unused now that MacroExpansionExpr always has an
argument list, and goes through the AddMissingArguments constraint fix for
this error.
2023-01-31 17:45:31 -08:00
Holly Borla
26786c1e09 [Macros] Make macro expansions always have an argument list. If an explicit
argument list isn't written, an implicit, empty list is created.
2023-01-31 17:04:35 -08:00
Alex Hoppen
1e05bd858e Merge pull request #62833 from ahoppen/ahoppen/allow-closure-with-error
[Sema] Don’t fail constraint generation if a closure contains an ErrorExpr
2023-01-31 21:17:27 +01:00
Alex Hoppen
17d47bb691 [Sema] Don’t fail constraint generation if a closure contains an ErrorExpr
It appears like this was missed in #60062.
2023-01-30 17:36:36 +01:00
Anthony Latsis
792a9cf7c0 [DiagnosticsQoI] Sema: Use 'underlying' instead of 'concrete' in opaque result type diagnostic 2023-01-28 20:51:40 +03:00
Luciano Almeida
f441e271a8 Merge pull request #62924 from LucianoPAlmeida/opaque-diags
[Diagnostics] Improving diagnostics for inference of opaque result concrete type
2023-01-18 08:38:26 -03:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Luciano Almeida
c6ea1f6611 [Diagnostics] Improving diagnostics for inference of opaque result concrete type 2023-01-09 09:41:54 -03:00
Holly Borla
c363fa2510 [Diagnostics] Make same-shape requirement failure diagnostics less sensitive
to binding order.
2023-01-07 09:50:14 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Doug Gregor
71ca9c86e6 [Macros] Diagnose when we forget to provide macro arguments.
Unlike functions, you can't curry macros; diagnose when one omits the
arguments in a macro expansion of a macro that has a parameter list.
2023-01-02 21:22:04 -08:00
Doug Gregor
806b5a8777 [Macros] Diagnose errors where a macro is used without the '#'. 2023-01-02 21:22:04 -08:00
Doug Gregor
af49a90dde Customize diagnostic text for extra/missing/mislabeled arguments for callee kind
Most of the diagnostics for extra/missing/mislabeled arguments refer
to argument to a "call". Some (but not call) would substitute in
"subscript". None would refer to an argument to a macro expansion
properly.

Rework all of these to refer to the argument in a call, subscript, or
macro expansion as appropriate. Fix up lots of tests that now say
"subscript" instead, and add tests for macro expansions.
2023-01-02 21:22:04 -08:00
Doug Gregor
bdc01ea985 [Macros] Handle macro argument lists in diagnostics
This improves diagnostics for missing/extra/incorrectly-labeled arguments.
2023-01-02 21:22:04 -08:00
Holly Borla
e966b4ef7d [CSDiagnostics] Add an error message for pack expansion expressions over
packs that don't have the same shape.
2022-12-21 08:25:10 -05:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Pavel Yaskevich
3c0401c7cb [CSDiagnostics] NFC: Prioritize sequence element over other contextual element diagnostics 2022-10-31 12:21:45 -07:00
Pavel Yaskevich
c0e09cb0dc [CSDiagnostics] Simplify MissingContextualConformanceFailure and avoid storing diagnostic
Carrying diagnostic through the method is becoming unmanagable and
prune to issues due to "in-flight" diagnostic replacement.
2022-10-31 12:21:45 -07:00
Pavel Yaskevich
8ab37ca449 [Diagnostics] Diagnose type with mismatching generic arguments in ternary expr
Fixes a missing diagnostic related to types with mismatched
generic arguments in one of both ternary branches.

Resolves: rdar://98862079
2022-10-27 15:56:50 -07:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Pavel Yaskevich
1a79d93121 Merge pull request #40702 from calda/cal--implicit-weak-self
[SE-0365] Allow implicit self for `weak self` captures
2022-09-30 10:30:57 -07:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Cal Stephens
5946c66962 Style updates 2022-09-23 07:09:52 -07:00
Cal Stephens
84896edaf2 Use Ctx.Id_self and update comments 2022-09-15 20:01:40 -07:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Hamish Knight
6804623a82 Fix some nullptr dereferences
Turns out we were getting away with dereferencing
`nullptr` in a few cases as `walk` would use
`nullptr` to indicate that the walk should be
stopped, and luckily Clang didn't optimize it to
something broken.

This commit is fairly defensive and sprinkles
some null checks for calls to `walk` directly
on a body of a function or top-level code decl.
2022-09-13 10:35:28 +01:00
Cal Stephens
9167a177cc Merge branch 'main' into cal--implicit-weak-self 2022-09-11 10:24:55 -07:00
Holly Borla
34d962461f Merge pull request #60671 from hborla/invalid-existential-access
[Diagnostics] Improve diagnostics for invalid type access on existential types.
2022-08-22 19:39:50 -04:00
Holly Borla
ddb5c13ef5 [Diagnostics] Improve the diagnostics for invalid type access on an
existential type in expression context.
2022-08-19 22:22:43 -04:00