Commit Graph

182 Commits

Author SHA1 Message Date
Pavel Yaskevich
b7a7024e0a [ConstraintLocator] Add information about expected value type to key path locator
Record a "value" type associated with this location to be able to
reference during inference.
2021-05-28 17:51:58 -07:00
Strieker
4e2b67cbae [NFC] Resolved merge conflict in CSSimplify.cpp after making changes to improve error handling for composed wrapped value mismatches 2021-04-22 11:49:21 -07:00
Strieker
3891dc7fdc [ConstraintSystem] Added necessary logic so that a constraint locator can recognize a composed property wrapper’s wrapped value type. 2021-04-22 11:31:41 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
d6fc1fd60f Implement conversions for global-actor-qualified functions.
One can convert from a function value without a global actor to a
similar function type that does have a global actor, but one cannot
remove or change a global actor on a function type.
2021-03-17 00:51:26 -07:00
Pavel Yaskevich
389fd29e6c [ConstraintSystem] Add a path element to represent an implicit conversion 2021-03-17 00:18:06 -07:00
Pavel Yaskevich
fb89d11931 [ConstraintLocator] NFC: Adjust name of isForKeyPathComponent to clarify its meaning
New name is `isInKeyPathComponent` since it's implemeneted as a
check for presence of `KeyPathComponent` element in the locator
that covers every sub-element contained in a key path component
as well.
2021-03-12 09:58:54 -08:00
Pavel Yaskevich
a8ad32d55b [ConstraintLocator] Add a new locator accessor to check whether it belongs to key path component result 2021-03-12 09:27:18 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Pavel Yaskevich
114364873d [ConstraintSystem] Adjust ConformanceRequirement locator to carry ProtocolConformance 2021-01-08 11:34:26 -08:00
Pavel Yaskevich
dbfeb5eea1 [ConstraintLocator] Add a new locator path element - ConformanceRequirement
Records protocol requirement associated with a particular type in
the constraint system, also useful to track parent conformance
for conditional requirements.
2021-01-06 10:13:55 -08:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
2020-10-26 00:40:45 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
f2614dec4a [ConstraintSystem] NFC: Move ConstraintLocator.h to include/swift/Sema 2020-10-08 10:42:39 -07:00
Pavel Yaskevich
e254f1c3e2 [ConstraintSystem] Infer whether locator is related to return of a single-expression function
This information could be inferred from state recorded in a
constraint system, so to need to record that in the
constraint locator as well.
2020-10-01 11:49:30 -07:00
Frederick Kellison-Linn
1069fe280f Fixup diagnostics 2020-08-26 22:42:29 -04:00
Holly Borla
2cfb5fa326 [ConstraintLocator] Simplify ConstraintLocator::Profile.
Since each kind of path element stores only one type of data, the path
element kind and the raw storage value are sufficient for uniquing the
element.
2020-08-13 14:56:17 -07:00
Holly Borla
b1c513de34 [ConstraintLocator] Add a isFirstElement helper function 2020-07-28 15:02:47 -07:00
Holly Borla
9baca13088 [Function Builders] Teach diagnostics about function builder body
result types in order to properly diagnose requirement failures that
aren't anchored at an expression.
2020-07-27 18:28:27 -07:00
Pavel Yaskevich
3e9e253acb [ConstraintSystem] Add a new locator element - argument attribute
`ArgumentAttribute` points to a particular attribute associated
with one of the arguments e.g. `inout` or its type e.g. `@escaping`.

This is very useful when dealing with argument-to-parameter
failures because it allows to express in the locator kind
of a problem.
2020-05-18 13:08:19 -07:00
Pavel Yaskevich
740a2dd4ad [ConstraintSystem] NFC: Inline ConstraintLocator::directlyAt implementation into the header 2020-04-29 17:03:45 -07:00
Pavel Yaskevich
955f0f3dbb [ConstraintSystem] Switch ConstraintLocator to use ASTNode as an anchor type 2020-04-29 17:03:45 -07:00
Pavel Yaskevich
7bdf0164d4 [ConstraintSystem] Replace remaining uses of TypedNode::dyn_cast with getAsExpr 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
099379a05c [ConstraintSystem] Switch ConstraintLocator to be anchored on TypedNode 2020-04-23 01:13:12 -07:00
Pavel Yaskevich
0ebdba06b5 [ConstraintSystem] Add a new locator element - type for body of a closure 2020-03-19 13:48:07 -07:00
Pavel Yaskevich
d5944ffa76 [ConstraintLocator] NFC: Introduce a way to determine whether locator points directly to a specific expression 2020-03-02 10:15:00 -08:00
Pavel Yaskevich
d1a11cd1f2 [ConstraintLocator] Add an accessor to check whether locator points directly at try? 2020-03-02 09:02:24 -08:00
Doug Gregor
d607d3a068 [Constraint system] Custom diagnostics for failed pattern matches.
Extend the constraint system’s diagnostics with specific handling for
matching an enum element pattern that has a subpattern (i.e., to capture
associated values) against an enum case that does not have any associated
value. This brings diagnostics for the new code path on par with the existing
diagnostics of coercePatternToType.
2020-02-24 00:48:15 -08:00
Doug Gregor
dcf7ddeb3a [Constraint system] Generate constraints for EnumElement patterns.
Generate a complete set of constraints for EnumElement patterns, e.g.,

    case let .something(x, y)

Most of the complication here comes from the implicit injection of optionals,
e.g., this case can be matched to an optional of the enum type of which
`something` is a member. To effect this change, introduce a locator for
pattern matching and use it to permit implicit unwrapping during member
lookup without triggering an error.

Note also labels are dropped completely when performing the match,
because labels can be added or removed when pattern matching. Label
conflict are currently diagnosed as part of coercePatternToType, which
suffices so long as overloading cases based on argument labels is not
permitted.

The primary observable change from this commit is in diagnostics: rather
than diagnostics being triggered by `TypeChecker::coercePatternToType`,
diagnostics for matching failures here go through the diagnostics machinery
of the constraint solver. This is currently a regression, because
there are no custom diagnostics for pattern match failures within the
constraint system. This regression will be addressed in a subsequent
commit; for now, leave those tests failing.
2020-02-24 00:48:15 -08:00
Pavel Yaskevich
95d0d14a29 [ConstraintLocator] Add accessors for assignemnt and coerce expression 2020-02-05 12:11:01 -08:00
Pavel Yaskevich
e19ef090b4 [ConstraintSystem] Add a new locator element to denote branches of ternary operator
`TernaryBranch` with a boolean flag to identify "then" (true) or
"else" (false) branches of the ternary operator expression.
2020-01-07 09:11:37 -08:00
Hamish Knight
40d11716f7 [CS] Use custom locator element for callAsFunction
Introduce a `ImplicitCallAsFunction` locator path
element to represent an implicit member reference
to `callAsFunction`. Then adjust CSApply a little
to check whether it's finishing an apply for a
callable type, and if so build the implicit member
access.
2019-12-18 11:43:45 -08:00
Pavel Yaskevich
b0d01de99a [ConstraintSystem] Add a special locator element for implicit @dynamicCallable calls 2019-12-06 16:43:18 -08:00
Hamish Knight
3e34c8c1b2 [CS] NFC: Use SIMPLE_LOCATOR_PATH_ELT in a couple of switches
This avoids us having to add new cases in the common case
of adding a new simple locator element.
2019-11-21 16:21:57 -08:00
Robert Widmann
d890b8ad41 Remove some save-and-restores
An awful pattern we use throughout the compiler is to save and restore global flags just for little things.  In this case, it was just to turn on some extra options in AST printing for type variables. The kicker is that the ASTDumper doesn't even respect this flag. Add this as a PrintOption and remove the offending save-and-restores.

This doesn't quite get them all: we appear to have productized this pattern in the REPL.
2019-11-13 07:37:12 -08:00
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Holly Borla
99467b4cc9 [ConstraintLocator] Change ConstraintLocator::getGenericParameter to return
`nullptr` if the locator path does not terminate at a `GenericParameter` element.
2019-11-05 09:16:57 -08:00
Hamish Knight
7077a68b83 [Sema] Diagnose unsound pointer conversions
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
2019-11-03 08:42:25 -08:00
Hamish Knight
92c42ec791 [AST] Add @_nonEphemeral parameter attribute
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
2019-11-03 08:40:59 -08:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
5d1eeacbe4 Resolving conflicts 2019-10-23 07:25:55 -03:00
Pavel Yaskevich
5a12e956f1 [ConstraintSystem] Add a new "condition" locator path element
"Condition" path element is used to represent a condition expression
associated with `if` expression or ternary operator `? :`.

Locator has been changed in the way that it's now anchored from `if`
itself which simplifies down to condition expression it needed.
2019-10-22 15:00:37 -07:00
Luciano Almeida
4385dd854f Creating UnnecessaryCoercion warning fix 2019-10-21 23:03:12 -03:00
Hamish Knight
4cd1c2e6bc [CS] NFC: Inline getSummaryFlagsForPathElement 2019-10-15 10:12:49 -07:00
Hamish Knight
b6b492d76a [CS] Rename LocatorPathElt::Requirement
Rename to LocatorPathElt::ProtocolRequirement in
order to help avoid confusion with
LocatorPathElt::AnyRequirement.
2019-09-29 14:19:57 -07:00