Commit Graph

134 Commits

Author SHA1 Message Date
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
a014f15e75 [CS] Enforce that withPathElement is called on an lvalue
Locator builders keep a pointer to their underlying
locator, so it's not generally sound to extend an
rvalue locator builder.

This commit enforces that withPathElement is called
on an lvalue, and adds a couple more overloads of
getConstraintLocator to make it more convenient to
extend locators with multiple elements.
2019-11-27 17:13:50 -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
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
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
Robert Widmann
75670c1727 Merge pull request #27436 from CodaFi/signed-sealed-delivered
[NFC] Adopt TypeBase-isms for GenericSignature
2019-09-30 15:50:42 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -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
Hamish Knight
6d8b798789 [CS] Have isLastElement take a locator path elt class
This makes it consistent with `getLastElementAs`
and `castLastElementTo`.
2019-09-29 14:19:56 -07:00
Hamish Knight
9121a6e308 [CS] Define locator path elements with macros
This allows us to define a `LocatorPathElt`
subclass for each path element kind.
2019-09-29 14:19:56 -07:00
Owen Voorhees
6c5185f2e3 Improve diagnostic when attempting to pass an Array to a variadic argument
- Give a more specific diagnostic which indicates the parameter is variadic
- If the argument is an Array literal, offer to drop the brackets
2019-09-20 17:30:23 -07:00
Pavel Yaskevich
afc3408b60 [ConstraintSystem] De-prioritize missing member fix when base is contextual
Impact is higher if the base is expected to be inferred from context,
because a failure to find a member ultimately means that base type is
not a match in this case.
2019-09-13 22:35:53 -07:00
Hamish Knight
b8b93eb7f5 [CS] Add first-element casting methods for locators 2019-09-09 14:14:34 +01:00
Suyash Srijan
bd53fe355d Revert "[CS] Don't crash when default argument is magic literal and types don't match" 2019-08-31 00:54:37 +01:00
Holly Borla
0cdfda0eb9 Merge pull request #26541 from hborla/autoclosure-optional-ptr-conversion-diag
[Diagnostics] Improve the diagnostic for invalid optional pointer conversions for an autoclosure result type.
2019-08-20 10:58:33 -07:00
Hamish Knight
6e45ef1347 [CS] Add locator find[First/Last] members
These members provide a convenient way of getting the first or last
occurrence of a given kind of element in a locator's path.
2019-08-19 11:58:50 +01:00
Hamish Knight
c225d52873 [CS] Add locator last element casting members
These members provide a convenient way of casting the last element of
a locator to a given path element type.
2019-08-19 11:58:50 +01:00
Hamish Knight
a0919f73b0 [CS] Use subclasses to expose locator element info
Instead of adding specific accessors directly to
ConstraintLocator::PathElement, add subclasses that expose these
accessors.
2019-08-19 11:58:49 +01:00
Hamish Knight
258d05aab8 [CS] Assert that path element info isn't truncated 2019-08-19 11:58:49 +01:00
Hamish Knight
b5b41a5bbe [CS] Add specific accessors for path element info
This commit replaces the `getValue()` and `getValue2()` members on
`ConstraintLocator::PathElement` with specific accessors for each
expected path component kind. IMO this adds some clarity to the call
sites, especially for `getArgIdx()` and `getParamIdx()`.

In addition, this commit adds a private `getValue` member that can
access a value at a given index, which will make it easier to add a
third value in the future.
2019-08-19 11:58:49 +01:00
Holly Borla
34b6241fc9 [Diagnostics] Move fix creation of AllowAutoClosurePointerConversion from
`matchTypes` to `repairFailures`.

This change handles invalid inout-to-pointer, array-to-pointer, and string-
to-pointer autoclosure conversions in the same way.
2019-08-07 18:05:51 -07:00
Holly Borla
04f09d0406 [ConstraintLocator] Rename isAutoclosureResult to isForAutoclosureResult 2019-08-07 13:56:35 -07:00
Holly Borla
7679a5a433 [Diagnostics] Improve the diagnostic for invalid optional pointer conversions for an
autoclosure result type.

Skip `ConstraintLocator::OptionalPayload` when checking if we're in an autoclosure context for
an inout-to-pointer conversion. This lets us apply the `AllowAutoClosurePointerConversion`
constraint fix when the pointer is optional.

This resolves rdar://problem/53532404
2019-08-07 12:41:11 -07:00
Pavel Yaskevich
795a84ae6e [CSFix] Delay missing unwrap locator simplification until diagnostic
Instead of keeping two locators in the fix let's store only the
original locator and simplify it later in process of emitting
a diagnostic. That helps to avoid some duplicate work as well
as makes sure that locators supplied to the diagnostic always
have an anchor.

Resolves: rdar://problem/53344815
2019-07-28 21:09:44 -07:00
Suyash Srijan
1a1bff46d8 [CS] Don't crash when using magic literals as default arg
Squash all commits into one
2019-07-17 01:20:25 +01:00
Slava Pestov
c365ef32c6 Sema: Handle protocol compositions containing type variables in matchTypes()
We would previously fail to match something like (C<$T1> & P) against
(C<Int> & P) when the constraint kind was <= Subtype, because we would
fall back to a type equality test in that case.

However, this was only valid for protocol compositions without superclass
constraints since the superclass could contain a type variable on one
side of the constraint.

Fix this by adding support for protocol composition types to
matchDeepEqualityTypes().
2019-06-17 18:40:31 -04:00
Pavel Yaskevich
ba6a5e10f8 [ConstraintSystem] Replace special locator for return of single expr function with a flag on contextual type locator
It's only needed in one place in the constraint solver to allow
`() -> T` to `() -> ()` and `() -> Never` to `() -> T` for expressions
representing return of a single expression functions, so to simplify
contextual type handling in diagnostic and other places it would be
better to replace dedicated locator kind with a flag on existing `ContextualType`.

Resolves: rdar://problem/51641323
2019-06-12 10:13:44 -07:00
Pavel Yaskevich
37373587cb [ConstraintLocator] NFC: Add isForContextualType accessor 2019-05-29 10:26:05 -07:00
Pavel Yaskevich
29e79c66e1 [ConstraintLocator] NFC: Add a helper to return generic parameter if locator points to one 2019-05-29 10:26:04 -07:00
Pavel Yaskevich
1cc6f774a1 [ConstraintSystem] Improve contextual mismatch diagnostics for for ... in <expr> loop 2019-05-15 14:34:24 -07:00
Slava Pestov
e39d236b29 Sema: Simplify for ... in ... type checking 2019-05-15 14:34:18 -07:00
Pavel Yaskevich
43526d031c Merge pull request #24431 from xedin/diag-noescape-param-assignment
[ConstraintSystem] Improve @escaping parameter diagnostics
2019-05-04 20:09:31 -07:00
Pavel Yaskevich
21216d8ecd [ConstraintSystem] Detect and fix invalid refs in dynamic key path member lookup
KeyPath dynamic member lookup is limited to what key path itself
could do, so let's detect and diagnose invalid references just
like we do for regular key path expressions.

Resolves: rdar://problem/50376224
2019-05-02 15:02:11 -07:00
Pavel Yaskevich
943d89136c [ConstraintLocator] NFC: Add isForGenericParameter accessor 2019-05-01 18:22:31 -07:00
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
Pavel Yaskevich
448e04ee52 [ConstraintLocator] Add a special locator element to denote contextual type of single expr function 2019-04-24 10:05:38 -07:00
Pavel Yaskevich
a42bf065df [ConstraintSystem] Add a special locator for type of the key path expression 2019-04-23 15:17:24 -07:00
Brent Royal-Gordon
760d4be5e0 [ConstraintSystem] Add a KeyPathComponentResult locator path element
We’ll use this instead of the function result, except for subscript components, which are already structured similarly to subscript expressions.
2019-04-17 21:15:16 -07:00
Pavel Yaskevich
55bc16e785 [Diagnostics] Diagnose static member reference as a key path component 2019-04-15 23:42:34 -07:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Pavel Yaskevich
93f9cb1d2a [ConstraintLocator] Identify whether locator is a result of keypath dynamic member lookup or belongs to keypath subscript component 2019-04-10 13:51:19 -07:00
Pavel Yaskevich
3288299e1e [ConstraintSystem] Make sure that each index argument of keypath subscript is Hashable
Move checking for index Hashable conformance from CSApply (post-factum)
to the solver and use recorded conformance records complete subscript
components.
2019-04-10 13:50:34 -07:00
Pavel Yaskevich
e3ad92fbfb [ConstraintSystem] Allow to use keypath dynamic member lookup inside keypath expressions 2019-04-03 11:01:48 -07:00
Pavel Yaskevich
84167edde9 [ConstraintSystem] Add a special locator for keypath dynamic member lookup
New locator is going to store pointer to the base keypath declaration.
This information is useful to determine whether such keypath is appropriate
to access underlying properties/subscripts e.g. `WritableKeyPath` cannot be
used to access read-only storage.
2019-04-01 12:40:39 -07:00
Pavel Yaskevich
1c54c5a08b [ConstraintLocator] Add special locator for synthesized arguments 2019-02-25 17:07:26 -08:00