Commit Graph

2716 Commits

Author SHA1 Message Date
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Doug Gregor
beb43749f1 Suggest '&' when it is needed to pass an lvalue by reference.
Fixes <rdar://problem/11592572>.

Swift SVN r16944
2014-04-27 21:42:06 +00:00
Doug Gregor
35eecfe835 Speculatively suggest '!' when treating an AnyObject as a class.
Swift SVN r16943
2014-04-27 21:42:05 +00:00
Doug Gregor
1edd7a3986 Speculatively suggest '!' when treating an AnyObject as a class.
Swift SVN r16939
2014-04-27 20:41:03 +00:00
Doug Gregor
eaf2bf632f Speculatively fix optionals by unwrapping them with '!'.
Example:

test/Constraints/fixes.swift:54:9: error: value of optional type 'B?'
    not unwrapped; did you mean to use '!' or '?'?
  b = a as B
        ^
            !

Swift SVN r16938
2014-04-27 20:41:02 +00:00
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Joe Pamer
844ea3258c Support implicit conversions from AnyObject to String, if NSString is available as a bridging type. This addresses rdar://problem/16271835, rdar://problem/15257126 and rdar://problem/15288553.
Swift SVN r16834
2014-04-25 19:52:01 +00:00
Nadav Rotem
960a6f2892 Improve the diagnostics of access to non-mutating members.
Swift SVN r16446
2014-04-17 06:34:15 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
John McCall
27bdc3066a A.Type is a subtype of SomeProtocol.Type if
A is a subtype of SomeProtocol.

rdar://16562102

Swift SVN r16145
2014-04-10 01:09:58 +00:00
Joe Pamer
18f3bf67b0 More progress towards getting same-type constraints working correctly.
Swift SVN r16023
2014-04-07 21:31:52 +00:00
Doug Gregor
c5163307c1 Type checker: tighten up the conditions under which we add a "function conversion" score.
Swift SVN r15891
2014-04-03 20:31:32 +00:00
John McCall
cc0dcfed2e Allow protocol methods that return Self? to be
called on existentials.

Swift SVN r15774
2014-04-02 04:01:18 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
John McCall
1ed9c46fda Permit ! to do the AnyObject downcast magic through one level of
optional type.

Swift SVN r15306
2014-03-20 23:58:14 +00:00
John McCall
5531ffde25 Add a conversion from T? to @unchecked T?. This is not
a subtype conversion.

Swift SVN r15026
2014-03-14 04:43:46 +00:00
John McCall
e3f6be8631 Permit @unchecked T? to be coerced to T as a conversion.
Originally, I didn't want this because I felt it made
unchecked-optional too non-local --- it wasn't always
obvious that an assignment might crash because it was
implicitly dropping optionality.  And that's still a
concern!  But I think that overall, if we're prepared
to accept that that danger is inherent in @unchecked T?,
this is a more consistent model: @unchecked T? means
that we don't know enough about the value to say for
certain that nil is a real possibility, so we'll let
you coerce it to the underlying type, and that coercion
just might not be dynamically safe.  No more special
cases for calls and member access (to the user; of
course, to the implementation these are still special cases
because of lookup and overload resolution).

Swift SVN r14796
2014-03-07 21:57:36 +00:00
John McCall
3c1b765fa8 Comment the restricted conversions with their formal
reduction rules.

Swift SVN r14795
2014-03-07 21:57:35 +00:00
John McCall
8d9666f518 Unify the places where we simplify a conversion according
to a conversion restriction.

I'm pretty certain that this is *supposed* to be NFC, in that
any subtle differences between the two blocks are actually
inadvertent bugs.
Unify the two places that switch out on a conversion
restriction; I'm pretty sure they're supposed to be doing
the exact same thing, and that any differences between
flags/subFlags and whether to log the restriction kind
are inadvertent.

Swift SVN r14794
2014-03-07 21:57:35 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
John McCall
e38a2b9a08 Discourage constraint systems that use more unchecked forces.
This is in preparation for a change that allows unchecked-optional
values to be implicitly forced in all contexts.

Swift SVN r14704
2014-03-06 00:18:41 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
John McCall
d6335efd3f Make nil convert to both T? and @unchecked T?.
This was blocked by some type-checker issues:

First, we weren't registering a constraint restriction when
tail-recursing in matchTypes (as opposed to when creating
a disjunction because multiple conversions applied).  Do so,
and move the set of constraint restrictions to the constraint
system in order to make this simpler.  A large amount of similar
solver state is already there, and of course solving the system
already prospectively modifies the constraint graph.

Second, only set up a potential existential conversion when
working with concrete types.  Without this, we would fail to
typecheck conversions to optional protocol types, but not
optional class/struct/whatever types.  It's not clear whether
whether we should ever really be considering conversions when
either of the types is non-concrete.

I believe it was the second fix which removed a need for a !
in the NewArray test case.

Swift SVN r14637
2014-03-04 08:20:04 +00:00
Doug Gregor
0bde325327 Collapse 'DynamicSelf' into 'Self'.
Swift SVN r14377
2014-02-26 05:04:05 +00:00
Doug Gregor
4af20816a6 Make the interface type for an initializer in a protocol return 'Self'.
Swift SVN r14352
2014-02-25 21:54:31 +00:00
Doug Gregor
61c240c8a8 Allow construction of existential values based on an existential metatype value.
... but obviously not when we've statically derived the existential
metatype. This isn't quite the way I'd like to prohibit these issues,
but more work on existentials and metatypes is coming up shortly.


Swift SVN r14326
2014-02-25 00:32:31 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Doug Gregor
57cae45875 Remove some pointless "if (false &&"'s.
We can't trigger this yet because these diagnostics all fall into the
"expression does not type-check" bear trap anyway.


Swift SVN r14054
2014-02-18 22:18:17 +00:00
John McCall
ef4fb36c50 Only permit checked downcasts of an existential to a subtype,
not to an arbitrary type that's convertible to the existential.
Arbitrary conversions aren't necessarily reversible.

The specific test case in rdar://16041990 involves a downcast
to String instead of NSString; that's supportable in principle,
but it's at the very least a significant feature, and clearly
there are non-reversible conversions out there.

Swift SVN r14028
2014-02-18 02:27:31 +00:00
John McCall
99ae104980 Protocol conformance is a subtyping relationship, no
matter whether the target type is a class existential.

The subtype relation should form a lattice and be intrinsically
reversible; everything else is a conversion.

Swift SVN r14027
2014-02-18 02:27:29 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Doug Gregor
7a3b17a238 Look through @unchecked_option for function application.
Swift SVN r13475
2014-02-05 04:51:38 +00:00
Doug Gregor
b22321d89b Allow invocation of a DynamicSelf-returning method on an existential.
As part of this, rewrite the check to use interface types. It's
cleaner and more efficient.

Swift SVN r13353
2014-02-03 15:27:55 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Doug Gregor
bb7e07cab2 Remove outdated FIXME.
Swift SVN r12897
2014-01-24 04:13:11 +00:00
John McCall
e088646f9b The value-to-optional and optional-to-optional conversions
are subtype conversions.

Swift SVN r12843
2014-01-23 03:05:06 +00:00
John McCall
59ffc88fa7 When ranking constraint solutions, consider anything that causes
a function conversion to be bad.

This encourages the type-checker to place conversions within
closures rather than outside; the test case here crashed in
SIL verification because of that.  (Yes, that means that there's
an underlying problem still when the function conversion is
required; that's tracked by rdar://15875305.)  But in general,
function conversions are likely to be expensive, and it's good
to avoid them when possible.

The setup work to add SK_FunctionConversion was accidentally
committed as part of r12813.

Swift SVN r12839
2014-01-23 01:28:48 +00:00
John McCall
5c6b022cbe Track whether a constraint locator is part of a function
conversion, and use the same process to optimize isSimple()
as an afterthought.

Swift SVN r12813
2014-01-22 23:22:55 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +00:00
John McCall
9c415a3bed Remove the TrivialSubtype conversion kind and implement
its basic logic in libAST, which both makes it easier to
implement and makes it possible to use in the places that
should care about it, i.e. in IR-gen and SIL-gen.

Per Doug, none of the places that were introducing
trivial-subtype constraints really needed to do so rather
than just using subtype constraints.

Swift SVN r12679
2014-01-22 00:19:56 +00:00
Chris Lattner
16db07a5a2 revert r12277 now that subscriptdecls in protocol have getter/setters. NFC.
Swift SVN r12666
2014-01-21 22:47:15 +00:00
John McCall
7be7c20a27 Implicitly look through UncheckedOptional<T> when it's the
base of a member access or subscript.

Swift SVN r12345
2014-01-15 21:00:59 +00:00
Chris Lattner
5c23e3568c Fix a crash on subscript decls in protocols.
Swift SVN r12277
2014-01-14 04:33:45 +00:00
John McCall
817e80bde5 Implicit conversions for UncheckedOptional.
rdar://15189000
rdar://15189009

Swift SVN r12260
2014-01-13 23:15:03 +00:00
Chris Lattner
fb640dfc21 start removing Materialization logic from the type checker:
- MaterializeExpr can never be formed in an argument list (but 
  still can as the base object) so remove that case from CSApply.
- LValues never exist *inside* of tuples, so remove code related
  to that.



Swift SVN r11889
2014-01-04 05:36:11 +00:00
Chris Lattner
847cc6b739 add some more testcases, have sema reject (with a poor QoI error) invalid code
where a mutating getter is used on an rvalue.  This previously crashed silgen
because the rvalue has no address to pass @inout.


Swift SVN r11887
2014-01-04 04:51:13 +00:00