Commit Graph

255 Commits

Author SHA1 Message Date
Saleem Abdulrasool
42af06051d lib: simplify some pragma usage
When suppressing a warning for a single line, prefer to use `suppress`
to avoid the push/pop dance.
2025-01-21 09:15:07 -08:00
Slava Pestov
385d66f24e Sema: Remove ConstraintKind::OneWayEqual 2024-12-21 00:42:13 -08:00
Slava Pestov
bb55d9c59a Sema: Remove -experimental-one-way-closure-params 2024-12-19 13:14:11 -05:00
Pavel Yaskevich
1760bd1f1e [CSOptimizer] Remove an outdated optimization to compare resolved argument types with all else equal
This is already accounted for by `determineBestChoicesInContext`
and reflected in the overall score, which means that we no longer
need to use this in vacuum.
2024-12-17 11:36:39 -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
Slava Pestov
3400022c63 Sema: Remove ConstraintKind::SelfObjectOfProtocol 2024-10-22 20:14:43 -04:00
Slava Pestov
b44bff26b5 Sema: Fold Constraint::createFixedChoice() into Constraint::createBindOverload() 2024-10-22 20:14:42 -04:00
Slava Pestov
2eaec5a97f Sema: Remove Constraint::clone() 2024-10-22 20:14:42 -04:00
Slava Pestov
0de8428f34 Sema: Tail-allocate Constraint::Overload::Choice
OverloadChoice is rather large, 40 bytes.
2024-10-22 20:14:42 -04:00
Slava Pestov
a48591d71d Sema: Tail-allocate Constraint::TheFix
Most constraints don't have a fix, so we can tail-allocate the fix.
This saves 16 bytes per constraint, because it also eliminates some
padding.
2024-10-22 20:14:42 -04:00
Pavel Yaskevich
5a93255133 [ConstraintSystem] Introduce new LValueObject constraint 2024-08-29 10:10:14 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Holly Borla
d9aa8697ab [Concurrency] Teach the constraint system about .isolation on dynamically
isolated function values.
2024-03-13 22:23:31 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Pavel Yaskevich
2ee646f47b [ConstraintSystem] NFC: Generalize DefaultClosureType constraint
This constraint is useful in more places than closures because
it gives a way to provide a "fallback type" without it having
effect on inference.
2023-06-16 11:15:15 -07:00
Pavel Yaskevich
bbe305cd43 [ConstraintSystem] Add same-shape constraint
The constraint takes two pack types and makes sure that their
reduced shapes are equal. This helps with diagnostics because
constraint has access to the original pack expansion pattern
types.
2023-05-02 09:32:19 -07:00
Anthony Latsis
82ac9328ae [NFC] CS: Misc minor debug output tweaks
* Use fancy arrows (`→`) because they are distinct from and shorter than `->`,
  and fancier.
* We have two ways of demarcating locators: `@ <locator>` and `[[<locator>]];`.
  Stick to the first, which is shorter and clearer.
* 'attempting type variable' → 'attempting binding'. *Bindings* are attempted,
  not type variables.
* `considering ->` → `considering:`. I think a colon is semantically more fit
  and makes things easier to read if the considered constraint has arrows in its
  description or types. It’s also shorter this way.
2023-04-18 22:42:59 +03:00
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
509188630b [ConstraintSystem] Implement type checking for converting a tuple to a
pack using the `.element` syntax.
2023-02-28 22:56:59 -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
Pavel Yaskevich
6b3776456c Merge pull request #62053 from abdulowork/improve-type-checker-debugging-indentation
Improve indentation in type checker debugging output
2022-11-30 12:11:27 -08:00
Doug Gregor
8adee85cb6 [Macros] Add support for explicit generic arguments of macros.
Enable type checking support for explicitly specifying generic arguments to
a macro, e.g., `#stringify<Double>(1 + 2)`. To do so, introduce a new
kind of constraint that performs explicit argument matching against the
generic parameters of a macro only after the overload is chosen.
2022-11-28 18:32:43 -08:00
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Slava Pestov
731d903a43 Sema: Add ConstraintKind::ShapeOf 2022-10-25 12:55:04 -04:00
Holly Borla
032c511754 [ConstraintSystem] Add a PackElementOf constraint to delay mapping opened
element pattern types to pattern archetypes until after type variables are
resolved.
2022-10-24 19:46:44 -07:00
Slava Pestov
46d5fa68f9 Sema: Introduce ConstraintKind::SubclassOf 2022-10-21 22:17:38 -04:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Pavel Yaskevich
4edbaa4c1a Merge pull request #61103 from amritpan/format-fixes
[ConstraintSystem] Format fixes to the type inference debug output.
2022-09-15 09:28:28 -07:00
Pavel Yaskevich
164fa9c45d Revert "[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint"
This reverts commit ef0523fe29.
2022-09-14 11:35:27 -07:00
Amritpan Kaur
a4a72075fd [ConstraintGraph] Correct dis/conjunction indents. 2022-09-13 10:45:15 -07:00
Amritpan Kaur
64800d576e [Constraint] Pass solverState indents to ASTPrinter's dump so that AST printed during conjunction attempts are indented correctly. 2022-07-21 13:34:22 -07:00
Amritpan Kaur
7452fc9ec4 [Constraint] Line break before printing AST for conjunction step's syntactic element. 2022-07-21 13:31:32 -07:00
Amritpan Kaur
e07f49d0e8 [Constraint] Sort constraint printing by favored, unmarked, and disabled in that order for printing only. 2022-07-05 14:20:08 -07:00
Amritpan Kaur
f3dd7f68a8 [Constraint] Eliminate repetitive locators to make useful information easier to read. 2022-07-05 14:20:08 -07:00
Pavel Yaskevich
ef0523fe29 [ConstraintSystem] NFC: Remove obsolete ValueWitness constraint 2022-05-30 23:17:41 -07:00
Pavel Yaskevich
0a5b3f0727 [TypeChecker] SE-0324: Extend Swift -> C pointer conversions to inout
Fixes an oversight where `inout` -> C pointer conversion wasn't covered
by implementation of new pointer conversion semantics proposed by SE-0324.

Resolves: rdar://92583588
2022-05-25 20:55:22 -07:00
Pavel Yaskevich
6a65810d30 [Constraint] NFC: Rename ClosureBodyElement to SyntacticElement
`SyntacticElement` represents a statement, pattern, declaration,
condition, or expression and could originate from i.e. a closure,
a function or a result builder body.
2022-04-26 09:55:04 -07:00
Pavel Yaskevich
ceb78c091c [Constraint] NFC: Improve debug output of pattern binding element constraints 2022-03-08 21:37:40 -08:00
Robert Widmann
d44d8ec043 Allow Converting Pack Types to Tuples
Insert an implicit conversion from pack types to tuples with equivalent parallel structure. That means

1) The tuple must have the same arity
2) The tuple may not have any argument labels
3) The tuple may not have any variadic or inout components
4) The tuple must have the same element types as the pack
2021-12-16 08:51:38 -08:00
Pavel Yaskevich
46ff410a23 [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-12-03 10:53:50 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Hamish Knight
237338b504 Merge pull request #40224 from hamishknight/super-tuple-shuffle 2021-11-18 09:50:09 +00:00
Hamish Knight
da36a2cb88 [CS] Restore a type variable for compatibility with rdar://85263844
Despite being otherwise disconnected from the
constraint system, it's possible for it to affect
how we type-check tuple matches in certain cases.

This is due to the fact that:
- It can have a lower type variable ID than an
opened generic parameter type, so becomes the
representative when merged with it. And because it
has a different locator, this can influence
binding prioritization.
- Tuple subtyping is broken, as it's currently a
*weaker* relationship than conversion.

Therefore, temporarily restore this bit of logic
for language versions < 6. If possible, we should
try and fix tuple subtying in Swift 6 mode to not
accept label mismatches, so that it's not more
permissive than tuple conversion.

rdar://85263844
2021-11-17 17:06:19 +00:00
Pavel Yaskevich
3927f56dbd [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-11-15 16:42:04 -08:00
Hamish Knight
b8e4c676c6 [CS] Remove function component constraints
FunctionInput relies on being able to represent
parameter lists as tuples, which won't be possible
once parameter flags are stripped from tuple types.
FunctionResult is reasonable, but is currently
unused.
2021-10-12 09:51:45 +01:00
Pavel Yaskevich
67a721485f [ConstraintSystem] Compute variables referenced by conjunction elements incrementally
Attempting to pre-compute a set of referenced type variables
upfront is incorrect because parameter(s) and/or result type
could be bound before conjunction is attempted. Let's compute
a set of referenced variables before each element gets attempted.
2021-10-08 10:08:03 -07:00