Commit Graph

23610 Commits

Author SHA1 Message Date
swift-ci
c74fd074c6 Merge pull request #64280 from hamishknight/platypus
[CS] Allow ExprPatterns to be type-checked in the solver
2023-06-06 20:21:45 -07:00
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00
Hamish Knight
da86703e2a [CS] Fix coercePatternToType enum cast handling
Previously if the cast was unresolved, we would
emit a warning and bail with `nullptr`. This is
wrong, because the caller expects a `nullptr`
return to mean we emitted an error. Change the
diagnostic to an error to fix this. This may
appear source breaking, but in reality previously
we were failing to add the cast at all in this case,
which lead to a crash in SILGen. We really do
want to reject these cases as errors, as this
will give us a better opportunity to fall back to
type-checking as ExprPatterns, and better matches
the constraint solver type-checking.

Also while we're here, change the diagnostic for
the case where we don't have an existential context
type from the confusing "enum doesn't have member"
diagnostic to the pattern mismatch diagnostic.

rdar://107420031
2023-06-07 00:35:02 +01:00
Hamish Knight
b43d351197 [CS] Improve diagnostics a bit for pattern mismatch
There's still plenty of more work to do here for
pattern diagnostics, including introducing a
bunch of new locator elements, and handling things
like argument list mismatches. This at least lets
us fall back to a generic mismatch diagnostic.
2023-06-07 00:35:02 +01:00
Hamish Knight
0695917bbd [CS] Don't form conversion between switch subject and pattern
This is wrong because there's nowhere to put any
conversion that is introduced, meaning that we'll
likely crash in SILGen. Change the constraint to
equality, which matches what we do outside of the
constraint system.

rdar://107709341
2023-06-07 00:35:01 +01:00
Hamish Knight
7a137d6756 [CS] Allow ExprPatterns to be type-checked in the solver
Previously we would wait until CSApply, which
would trigger their type-checking in
`coercePatternToType`. This caused a number of
bugs, and hampered solver-based completion, which
does not run CSApply. Instead, form a conjunction
of all the ExprPatterns present, which preserves
some of the previous isolation behavior (though
does not provide complete isolation).

We can then modify `coercePatternToType` to accept
a closure, which allows the solver to take over
rewriting the ExprPatterns it has already solved.

This then sets the stage for the complete removal
of `coercePatternToType`, and doing all pattern
type-checking in the solver.
2023-06-07 00:35:01 +01:00
Hamish Knight
21e787bae8 [Sema] Walk SyntacticElementTarget for completion
Instead of walking the single ASTNode from the
target, walk all AST nodes associated with the
target to find the completion expr. This is needed
to find the completion expr in a pattern for an
initialization target.
2023-06-07 00:35:01 +01:00
Hamish Knight
2a3b15c3e8 [CS] Remove null Type handling from getTypeForPattern
We should never CSGen a null Type for patterns.
2023-06-07 00:35:01 +01:00
Hamish Knight
7c514fcea4 [CS] Remove null pattern handling from getTypeForPattern
Push the only null case that can occur up into the
caller.
2023-06-07 00:35:01 +01:00
Hamish Knight
8d2f2baff0 [CS] Remove external type logic from getTypeForPattern
This shouldn't be necessary, we should be able to
solve with type variables instead. This makes sure
we don't end up with weird special cases that only
occur when an external type is present.
2023-06-07 00:35:00 +01:00
Hamish Knight
23dbf6f106 [CS] Reverse the type order in a couple of pattern equality constraints
Order them such that if they were changed to
conversions, they would be sound. This shouldn't
make a difference, but unfortunately it turns out
pattern equality is not symmetric. As such, tweak
the pattern equality logic to account for the
reversed types. This allows us to remove a special
case from function matching.
2023-06-07 00:35:00 +01:00
Hamish Knight
f3b16fd7ad [CS] Fix a couple of constraints in getTypeForPattern
The TypedPattern and IsPattern constraints were
incorrectly written, with conversions propagating
out of the patterns, when really conversions
ought to propagate into patterns. In any case, it
seems like we really want equality here. Fix the
constraints to use equality, and have the cast
constraint operate on the external pattern type
instead of the subpattern type.
2023-06-07 00:35:00 +01:00
Slava Pestov
6eb112e3b6 AST: Factor out duplication between PackTypeParameterCollector and PackTypeVariableCollector 2023-06-06 14:18:37 -04:00
Slava Pestov
55a253a80b Sema: Variadic generic type aliases don't require runtime support 2023-06-06 14:18:37 -04:00
Michael Gottesman
cbb9e157e7 Restore sema code that bans consuming from being applied to no escape functions. 2023-06-06 12:42:23 -04:00
Michael Gottesman
95cdf2a084 Revert "temporarily prevent Copyable types from using consuming and borrowing"
This reverts commit 8899d3b702.
2023-06-06 12:37:49 -04:00
Rintaro Ishizaki
a61fa5a4c2 Merge pull request #66296 from rintaro/macros-freestandingexpansion
[Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic
2023-06-05 09:35:18 -07:00
Doug Gregor
d12eae4e12 Merge pull request #66320 from DougGregor/macro-operators-without-global-operator-lookup
Eliminate macro-generated operators from global operator lookup
2023-06-04 21:21:36 -07:00
Doug Gregor
b7b6a1db72 Ensure that macro-provided operators can be found by witness lookup
When looking for an operator to satisfy a protocol requirement, we
currently depend on global operator lookup for everything except local
types. However, macro-provided operators aren't found by global
operator lookup, so perform a member lookup for such cases in addition
to global operator lookup. This makes macro-provided operators visible
through protocol requirements they witness.
2023-06-03 23:19:24 -07:00
Joe Groff
3582691e65 Merge pull request #66302 from jckarter/noncopyable-switch-require-consume
Require `switch` on a noncopyable-type binding to be explicitly `consumed`.
2023-06-03 12:08:26 -07:00
Joe Groff
359e045192 Require switch on a noncopyable-type binding to be explicitly consume-d.
Pattern matching as currently implemented is consuming, but that's not
necessarily what we want to be the default behavior when borrowing pattern
matching is implemented. When a binding of noncopyable type is pattern-matched,
require it to be annotated with the `consume` operator explicitly. That way,
when we introduce borrowing pattern matching later, we have the option to make
`switch x` do the right thing without subtly changing the behavior of existing
code. rdar://110073984
2023-06-02 18:14:37 -07:00
Rintaro Ishizaki
86d405bcd0 [Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic
'MacroExpansionDecl' and 'MacroExpansionExpr' have many common methods.
Introduce a common base class 'FreestandingMacroExpansion' that holds
'MacroExpansionInfo'.

Factor out common expansion logic to 'evaluateFreestandingMacro'
function that resembles 'evaluateAttachedMacro'.
2023-06-02 11:54:05 -07:00
Slava Pestov
7499c222ee AST: Requestify lookup of protocol referenced by ImplementsAttr
Direct lookup relied in primary file checking to have filled in the
protocol type stored in the ImplementsAttr. This was already wrong
with multi-file test cases in non-WMO mode, and crashed in the
ASTPrinter if printing a declaration in a non-primary file.

I don't have a standalone test case that is independent of my
upcoming ASTPrinter changes, but this is a nice cleanup regardless.
2023-06-02 13:17:25 -04:00
Slava Pestov
76d9154474 Sema: Add a simpler form of checkGenericArguments() 2023-06-01 22:36:24 -04:00
Holly Borla
14e92b2678 [Macros] Don't apply member attribute macros to expanded members. 2023-05-31 17:14:39 -07:00
Rintaro Ishizaki
94f810906c Merge pull request #66233 from rintaro/macros-creatsourcefile
[Macros] Factor out SourceFile creation for macro expanded buffer
2023-05-31 10:30:38 -07:00
Luciano Almeida
1d90de16c7 Merge pull request #66208 from LucianoPAlmeida/diag-ternary
[Sema] Increase impact of ternary then branch aiming better diagnostics
2023-05-31 01:24:43 -03:00
Luciano Almeida
fef908efac [Sema] Increase impact of ternary then branch aiming better diagnostics 2023-05-30 20:55:50 -03:00
Rintaro Ishizaki
78b22295a4 [Macros] Factor out SourceFile creation for macro expanded buffer
Introduce 'createMacroSourceFile()' that creates macro expanded
'SourceFile' object. Use it from various macro expansion functions.
2023-05-30 15:21:15 -07:00
Sophia Poirier
0594efc0ce Merge pull request #66214 from sophiapoirier/tuple-expansion-without-dot-element
[Variadic Generics] drop requirement of .element for tuple expansion
2023-05-30 16:29:55 -04:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Doug Gregor
7386a7e7bd [Macros] Rework the way we assign closure and local discriminators
Setting closure and local discriminators depends on an in-order walk
of the AST. For macros, it was walking into both macro expansions and
arguments. However, this doesn't work well with lazy macro expansions,
and could result in some closures/local variables not getting
discriminators set at all.

Make the assignment of discriminators only walk macro arguments, and
then lazily assign discriminators for anything within a macro
expansion or in ill-formed code. This replaces the single global "next
autoclosure discriminator" scheme with a per-DeclContext scheme, that
is more reliable/robust, although it does mean that discriminators
of closures and locals within macro expansions are dependent on
ordering. That shouldn't matter, because these are local values.

Fixes rdar://108682196.
2023-05-28 16:49:20 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Richard Wei
47d3b180a5 Merge pull request #66132 from rxwei/109779928
[Macros] Fix existential diagnostics for declaration macro expansions
2023-05-26 11:06:10 -07:00
Slava Pestov
9b3faad523 Merge pull request #66126 from slavapestov/pack-element-refactoring
Preliminary work for introducing PackElementType
2023-05-26 09:13:53 -04:00
Richard Wei
7502f3ce83 [Macros] Fix existential diagnostics for declaration macro expansions
`TypeChecker::checkExistentialTypes` has decl-specific logic and backs out without invoking `ExistentialTypeVisitor` on `TypeDecl`s, but `MacroExpansionDecl` isn't a type decl and would fall into `ExistentialTypeVisitor` which will visit its expansion. The caller of `checkExistentialTypes` already visits auxiliary decls, so here we should only visit arguments and generic arguments of a macro.

Fixes a case where a declaration macro produces a type that conforms to a PAT. We now also run existential diagnostics on generic arguments on a `MacroExpansionDecl` that was previously not handled.

Note: I tried bailing out in `walkToDeclPre` but we should really visit macro arguments and generic arguments. Not walking expansions in `ExistentialTypeVisitor` is also not the right fix because we need to be able to visit macro expansions in arguments.

rdar://109779928
2023-05-25 23:25:58 -07:00
Becca Royal-Gordon
b2d0f25215 Merge pull request #66114 from beccadax/implementation-warnings
[NFC] Use method for more @objcImpl diagnostics
2023-05-25 08:44:18 -07:00
Slava Pestov
9d5b6d8e27 Sema: Remove unused local variable 2023-05-25 11:35:00 -04:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Konrad `ktoso` Malawski
d685c1c67d Merge pull request #66119 from ktoso/wip-distributed-ban-__owned 2023-05-25 16:58:45 +02:00
swift-ci
47206732f5 Merge pull request #66090 from kavon/noncopyable-diagnostics-cleanup
polish up the noncopyable diagnostics
2023-05-25 02:07:06 -07:00
Konrad `ktoso` Malawski
6e14025b95 [Distributed] Explicitly ban __owned and other specifiers we dont support 2023-05-25 10:59:01 +02:00
Kavon Farvardin
31aa2f77e3 polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable"
- replaces compiler jargon like "guaranteed parameters"
  and "lvalue" with corresponding language-level notions
- simplifies diagnostics about closures.

and probably more.

rdar://109281444
2023-05-24 20:56:36 -07:00
Doug Gregor
22c987e43f Merge pull request #66093 from DougGregor/se-0397-enable-by-default 2023-05-24 18:55:39 -07:00
Becca Royal-Gordon
c93e4896c0 [NFC] Use method for more @objcImpl diagnostics 2023-05-24 16:53:02 -07:00
Becca Royal-Gordon
5c1ce9af80 Merge pull request #66073 from beccadax/implementation-errors
Diagnose additional @objcImpl member mismatch errors
2023-05-24 16:49:30 -07:00
Kavon Farvardin
6c5eaae19a [nfc] delete dead code 2023-05-24 15:53:21 -07:00
Pavel Yaskevich
acf64e3c15 Merge pull request #66080 from xedin/rdar-109586440
[ConstraintSystem] Some more variadic generic fixes
2023-05-24 14:49:09 -07:00
Doug Gregor
cfda29ccd4 [SE-0397] Enable freestanding declaration macros by default.
This proposal has been accepted. Move the feature flag from "experimental"
to "always enabled". Tracked by rdar://108637367.
2023-05-24 09:16:55 -07:00
Becca Royal-Gordon
9f0928e239 Match @objcImpl member types
Check the types of @objcImpl candidates against their requirements and diagnose *most* mismatches.

Unlike typical type matching rules, @objcImpl allows an implementation’s parameter *and* result types to be an IUO when the requirement isn’t. This runs against the normal covariance rules in the case of the result type. It’s meant to allow an implementation to handle nils passed to it and return nils even if the declaration formally claims nils are not permitted; this is occasionally necessary to reimplement Objective-C APIs without breaking ABI compatibility.

Fixes rdar://102063730.
2023-05-23 11:34:51 -07:00