Commit Graph

34 Commits

Author SHA1 Message Date
Pavel Yaskevich
b8c25db47e [ConstraintSystem] Add keypath subscript choice only if argument has an expected label
Currently only valid way to form keypath subscript is to use `keyPath:`
label in subscript invocation, so let's avoid adding keypath overload
choice to every subscript lookup and instead only add it when it could
potentially match.

This among other things greatly helps diagnostics because sometimes
`keypath application` becomes the only choice even although it's
not really viable, which impedes member reference diagnostics.
2019-07-03 00:48:04 -07:00
Hamish Knight
8aa7401ba5 [Sema] Add getDeclOrNull to OverloadChoice
This helps clean up a bunch of call sites.
2019-05-16 12:07:41 +01:00
Pavel Yaskevich
f95d9b092e [TypeChecker] Add new type of overload choice to support keypath dynamic lookup 2019-04-01 12:40:39 -07:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Dan Zheng
2863b6cc64 Gardening for @dynamicMemberLookup. (#20498)
* Gardening for `@dynamicMemberLookup`.

- Unify code style of `@dynamicMemberLookup` and `@dynamicCallable` implementations.
  - Use consistent variable names, diagnostic messages, doc comments, etc.
- Move `@dynamicMemberLookup` test to `test/attr` directory.
2018-11-11 21:54:19 -05:00
Sho Ikeda
3c399de5bd [gardening][Sema] Replace typedef with using 2018-04-03 22:12:48 +09:00
Mark Lacey
b9cd30331d [ConstraintSystem] Do not attempt to force references of unapplied functions.
We were inserting function conversion expressions that were then
turned into forces of values in cases where we merely referenced
functions, but did not actually call them.

Fixes rdar://problem/37241550.
2018-02-20 17:49:10 -08:00
Chris Lattner
a0fa5d11b4 Implement SE-0195, which introduces "Dynamic Member Lookup" Types (#14546)
* Implement the recently accepted SE-0195 proposal, which introduces "Dynamic
Member Lookup" Types.  This is a dusted off and updated version of PR13361,
which switches from DynamicMemberLookupProtocol to @dynamicMemberLookup as
was requested by the final review decision.  This also rebases it,
updates it for other changes in the compiler, fixes a bunch of bugs, and adds support for keypaths.  

Thank you to @rudx and @DougGregor in particular for the helpful review comments and test cases!
2018-02-16 16:19:50 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Mark Lacey
d1bb36425d IUO: Add overload choice kind for IUO decls.
Add a new OverloadChoiceKind for decls that are either IUO-typed, or
function-typed meaning that the function result type is IUO-typed.

Not currently used, so NFC.
2018-01-03 19:37:06 -08:00
Chris Lattner
0670deffcb Rework OverloadChoice to use PointerEmbeddedInt instead of reimplementing it
in a gross way.  Also, handle DeclViaDynamic the same way as DeclViaBridge
and DeclViaUnwrappedOptional.

Also, OverloadChoiceKind says that TupleIndex must be the last entry in the
enum list, so make it the last one (even though this doesn't actually cause
a bug right now).

All this is just cleanup, NFC.
2017-11-24 17:17:22 -08:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
a6dfcd52cf Sema: Remove OverloadChoiceKind::TypeDecl, which was never used 2017-05-23 02:10:02 -07:00
Joe Groff
7eebb27153 Sema: Infer the specific type of a key path literal from the mutability of the resolved components. 2017-04-10 16:06:40 -07:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
71df32fd7d Sema: Add some asserts 2017-01-04 01:08:28 -08:00
Joe Groff
1889fde228 Resolve type(of:) by overload resolution rather than parse hackery.
`type(of:)` has behavior whose type isn't directly representable in Swift's type system, since it produces both concrete and existential metatypes. In Swift 3 we put in a parser hack to turn `type(of: <expr>)` into a DynamicTypeExpr, but this effectively made `type(of:)` a reserved name. It's a bit more principled to put `Swift.type(of:)` on the same level as other declarations, even with its special-case type system behavior, and we can do this by special-casing the type system we produce during overload resolution if `Swift.type(of:)` shows up in an overload set. This also lays groundwork for handling other declarations we want to ostensibly behave like normal declarations but with otherwise inexpressible types, viz. `withoutActuallyEscaping` from SE-0110.
2016-12-22 16:28:31 -08:00
practicalswift
9d0b2abfc2 [gardening] Normalize end-of-namespace comments 2016-12-17 22:29:07 +01:00
Hugh Bellamy
48109f2a64 Fix errors and warnings building libSwiftSema on Windows using MSVC 2016-11-29 11:24:13 +00:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
a9536906ff [SE-0111] Drop argument labels on references to function values.
When referencing a function in the type checker, drop argument labels
when we don't need them to type-check an immediate call to that
function. This provides the semantic behavior of SE-0111, e.g.,
references to functions as values produce unlabeled function types,
without the representational change of actually dropping argument
labels from the type system.

At the moment, this only works for bare references to functions. It
still needs to be pushed through more of the type checker and more AST
nodes to work in the general case.

Keep this work behind the frontend flag
-suppress-argument-labels-in-types for now.
2016-07-28 15:40:11 -07:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
d3d559fce6 Fix typo: declaraton → declaration 2015-12-14 00:11:34 +01:00
Devin Coughlin
c1caddae62 Remove experimental support for treating unavailable symbols as optional.
This has always been off by default and is a language direction we have decided not to
pursue.

Swift SVN r30355
2015-07-18 01:56:25 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Devin Coughlin
3749a98763 Record the reason a declaration is potentially unavailable.
This commit adds tracking of the reason a declaration reference is potentially
unavailable to the UnavailableToOptionalExpr AST node and to OverloadChoice. We
will use this reason during SILGen to emit the appropriate run-time check and
during typechecking to provide more helpful diagnostics.

To keep OverloadChoice as small as possible, we encode the reason as an index
into a vector of reasons stored in a given instance of ConstraintSystem (this is
the same approach that Fix takes).

This commit adds Sema/OverloadChoice.cpp (for the parts of OverloadChoice that
now rely on ConstraintSystem) and AST/Availability.h (to bring in
availability-related structures without TypeRefinementContext).


Swift SVN r22377
2014-09-30 01:53:59 +00:00
Devin Coughlin
b727b6d932 Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
2014-09-24 00:07:46 +00:00
Joe Groff
3c539b7f24 Sema: Look through optional types for .member lookup.
When we see a '.member' expression in optional context, look for the member in the optional's object type if it isn't found in Optional itself. <rdar://problem/16125392>

Swift SVN r19469
2014-07-02 16:33:45 +00:00
Doug Gregor
1c06c309bc Automatically reflect non-Foundation categories of bridged Objective-C classes onto their bridged value types.
This makes categories of NSString, NSArray, and NSDictionary available
on String, Array, and Dictionary. Note that we only consider
categories not present in the Objective-C Foundation module, because
we want to manually map those APIs ourselves. Hence, no changes to the
NSStringAPI. Implements <rdar://problem/13653329>.


Swift SVN r18920
2014-06-16 09:07:00 +00:00
Doug Gregor
edad9e45e5 Remove OverloadChoiceKind::IdentityFunction.
It's unused now.


Swift SVN r10790
2013-12-04 21:14:47 +00:00
Doug Gregor
8f439ae6ce Remove unused OverloadChoiceKind::FunctionReturningBaseType.
Swift SVN r10627
2013-11-21 06:31:31 +00:00
Doug Gregor
16901477c2 Introduce an overload-binding constraint.
Overload bindings constraints bind a given type to a specific overload
choice. This is a step toward moving overload sets into normal
disjunction constraints.

Part of the work here is to eliminate the constraint system's
dependence on OverloadSet, which will be going away in favor of a
disjunction constraint.


Swift SVN r9209
2013-10-11 18:27:51 +00:00
Doug Gregor
1a95c47652 Split OverloadChoice into its own header.
Swift SVN r9205
2013-10-11 17:38:39 +00:00