Commit Graph

673 Commits

Author SHA1 Message Date
Doug Gregor
2653a6569b Eliminate ModuleExpr; DeclRefExpr is good enough for anyone.
Swift SVN r28285
2015-05-07 21:10:53 +00:00
Doug Gregor
297c9e2911 Introduce NameLookupOptions for TypeChecker::lookupMember(). NFC
Swift SVN r28281
2015-05-07 21:10:38 +00:00
Chris Willmore
cfd450391b Don't mutate defaultArgsOwner with getCallerDefaultArg() directly, so we
can make a more precise assertion that all default arguments have the
same owner.

<rdar://problem/20749423> Compiler crashed while building simple subclass code

Swift SVN r28251
2015-05-07 01:18:24 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +00:00
Chris Willmore
f3670d3a6f When adding '!' in fix-it, make sure that it doesn't fall into the
optional evaluation context that produced the optional.

<rdar://problem/20377684> Oscillating fixit for optional chain calling method that returns non-optional

Swift SVN r28212
2015-05-06 19:05:45 +00:00
Doug Gregor
83d336e714 Stop using TupleTypeElts in the type checking for arg/param matching.
Instead, use a dedicated struct. NFC

Swift SVN r28207
2015-05-06 17:05:27 +00:00
Chris Willmore
6263024a91 Coerce UnresolvedMemberExpr to its assigned type if it has an argument,
since the type might not match the return type of the function exactly
in that case (CSGen only emits a conversion constraint).

<rdar://problem/20087517> Crash when using .staticShorthand syntax with NSColor/UIColor factories

Swift SVN r28200
2015-05-06 08:25:05 +00:00
Doug Gregor
158e23f427 Make sure that we complete any conformances that are used in the AST.
When semantic analysis forms a reference to a conformance that will
persist in the AST (it is "used" in the C++ odr-used sense), complete
that conformance before type checking terminates. This ensures that
the SIL optimizers have complete conformances to work with for, e.g.,
generic specialization. Fixes rdar://problem/20735544.

Swift SVN r27896
2015-04-29 00:08:27 +00:00
Doug Gregor
a30ca2a60d Replace bool parameter to TypeChecker::conformsToProtocol() with an option set.
NFC; we can extend this option set more readily later.

Swift SVN r27894
2015-04-29 00:08:22 +00:00
Chris Lattner
8494651d22 Substantially rework CSApply's building of argument lists for calls.
This fixes <rdar://problem/20494437> SILGen crash handling default arguments
again, and includes a fix for MiscDiagnostics to look through the generated
TupleShuffleExprs in @noescape processing (which tripped up XCTest).

This fixes <rdar://problem/16860940> QoI: Strict keyword arguments loses type sugar in calls
where we'd lose some type sugar.

This fixes sanity in the ASTs: ScalarToTupleExpr now always has consistent
types between its argument and result, so we can turn on AST Verification of it.




Swift SVN r27827
2015-04-27 23:02:09 +00:00
Ted Kremenek
b9c10c048f Revert "fix <rdar://problem/20494437> SILGen crash handling default arguments"
This was breaking building the XCTest overlay.

Swift SVN r27818
2015-04-27 21:30:48 +00:00
Chris Lattner
d314ed1a0b fix <rdar://problem/20494437> SILGen crash handling default arguments
This was an ugly situation where we'd create an invalid ScalarToTuple in
a situation with default arguments, because CSApply didn't realize that the
default argument causes formation of a specific tuple kind with a single element.

There is more damage in this area, other work coming.


Swift SVN r27811
2015-04-27 19:33:22 +00:00
Chris Lattner
0e8f0d6bfc fix <rdar://problem/20679379> DI crashes on initializers on protocol extensions
DI makes the assumption that the type of self in an initializer is always
derived from a nominal type.  Now that you can put an initializer body on a
protocol, this isn't true anymore, so teach it about this.



Swift SVN r27714
2015-04-24 23:51:40 +00:00
Doug Gregor
02d25888c9 Clean up the interface to Type::subst(), NFC.
Replace the 'ignoreMissing' boolean flag with a new option set type,
SubstOptions, which is easier to extend. It is not an OptionSet<>
because a follow-on commit will introduce a non-trivial option that
will require more storage.

Also eliminate the LazyResolver parameter, which is no longer
needed. Eliminate the silly TypeChecker::substType(), whose only
purpose was to provide the resolver.

Swift SVN r27656
2015-04-23 23:36:18 +00:00
Doug Gregor
4ae7b13820 Stop trying to fully check a conformance when we query its existence.
This eliminates nonsensical recursion when working with protocol
conformances, and makes their checking more lazy. Start to improve
name lookup to deal with protocol witnesses more lazily, generalizing
the solution we had to all protocol conformances and making it more
directed. We're not done here, as the FIXMEs in the code completion
test imply: this replace-the-requirement-with-the-witness behavior
needs to be sunk down into the AST level so it also applies to
unqualified lookup, visible-decl lookup, etc.

Swift SVN r27639
2015-04-23 18:20:57 +00:00
Doug Gregor
c45c5d4bd1 Stop performing silly, ridiculous hasTypeWitness checks.
Swift SVN r27638
2015-04-23 18:20:56 +00:00
Slava Pestov
af5fb8a7b0 Fix conformances when calling protocol extension method with constraints
We need to use the constrants from the extension, otherwise we might
pass in the wrong witness method table at the call site, among other
problems.

Fixes rdar://problem/20532214.

Swift SVN r27585
2015-04-22 17:18:45 +00:00
Chris Willmore
4330f2a8a9 Instead of replacing ObjectLiteralExpr in CSApply, set its semantic expression (a la InterpolatedStringLiteralExpr).
Swift SVN r27488
2015-04-20 19:41:10 +00:00
Chris Willmore
d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.

Swift SVN r27479
2015-04-20 12:55:56 +00:00
Joe Pamer
006c182c13 Begin inferring throwing function types for closures. (There's more work to do here - hence the thin tests - but I need to investigate a couple of sema bugs before moving forward.)
Swift SVN r27438
2015-04-17 19:06:52 +00:00
Doug Gregor
69718f77fa When failing to find a suitable type witness, always record ErrorType.
Fixes the crash in rdar://problem/20564378. In these cases, we end up
swallowing some diagnostics. That will be addressed in a subsequent
commit.

Swift SVN r27436
2015-04-17 18:11:35 +00:00
Joe Groff
dfc57e6f01 Type checker: Don't attempt metatype-to-object conversions if ObjC interop is disabled.
The post-type-checking error that was here is arguably better QoI, but it is causing ambiguities that break the non-ObjC-compatible build in the stdlib. We shouldn't even attempt these conversions if there's no runtime support to back them up.

Swift SVN r27407
2015-04-17 05:30:16 +00:00
Nadav Rotem
f2169f8103 Silence a few more warnings in Release builds.
Swift SVN r27334
2015-04-15 21:38:23 +00:00
Devin Coughlin
d08b98b1ca Sema: Turn on availability checking by default
Enable checking for uses of potentially unavailable APIs. There is
a frontend option to disable it: -disable-availability-checking.

This commit updates the SDK overlays with @availability() annotations for the
declarations where the overlay refers to potentially unavailable APIs. It also changes
several tests that refer to potentially unavailable APIs to use either #available()
or @availability annotations.

Swift SVN r27272
2015-04-14 06:44:01 +00:00
Doug Gregor
997136962e Always open existential types in the type checker.
Consistently open all references into existentials into
opened-existential archetypes within the constraint solver. Then,
during constraint application, use OpenExistentialExprs to record in
the AST where an existential is opened into an archetype, then use
that archetype throughout the subexpression. This simplifies the
overall representation, since we don't end up with a mix of operations
on existentials and operations on archetypes; it's all archetypes,
which tend to have better support down the line in SILGen already.

Start simplifying the code in SILGen by taking away the existential
paths that are no longer needed. I suspect there are more
simplifications to be had here.

The rules for placing OpenExistentialExprs are still a bit ad hoc;
this will get cleaned up later so that we can centralize that
information. Indeed, the one regression in the compiler-crasher suite
is because we're not closing out an open existential along an error
path.

Swift SVN r27230
2015-04-11 03:20:22 +00:00
Doug Gregor
4ec1cb2537 Collapse creation of DynamicMemberRefExprs into the normal member-reference path. NFC
Swift SVN r27229
2015-04-11 03:20:15 +00:00
Joe Groff
7612df1918 Runtime: Rename 'becomeNSError' to 'bridgeErrorTypeToNSError'.
We may want to use optimized ErrorType representations that don't naturally "become" NSErrors, such as tagged-pointer representations of small error enums, or a tagged function pointer to a deferred error type constructor. Rename the runtime function to something a bit more descriptive of its real purpose, not its implementation.

Swift SVN r27209
2015-04-10 17:37:40 +00:00
Doug Gregor
5f4bea74e1 Open existential uses of dynamic-Self methods and initializers in the constraint solver.
Previously, we were only opening the existentials as part of
constraint application, which involved some ugly, redundant code. This
should be NFC because it's just moving the existential opening
operation earlier, but it's a step toward opening up all existential
references.

Swift SVN r27190
2015-04-09 23:58:55 +00:00
Doug Gregor
85b89ba112 Tighten up our handling of erasure of opened existentials. NFC
Swift SVN r27189
2015-04-09 23:58:54 +00:00
Roman Levenstein
d1698ba1cb Use a _bridgeable suffix for newly introduced fast bridging functions. NFC.
Dave explained that stdlib usually uses the suffix notation in such cases. This change follows his advice.

Swift SVN r27177
2015-04-09 20:59:42 +00:00
Doug Gregor
7fc1ac61ab Revert "Kill the sequence number in OpenedExistential."
This reverts r27106; we're going to need this for recovery.

Swift SVN r27170
2015-04-09 15:51:03 +00:00
Doug Gregor
6755aaf6b9 Revert "Simplify constraint application now that open-existentials are more local."
This reverts r27107; we're going to need this code for recovery.

Swift SVN r27169
2015-04-09 15:51:01 +00:00
Doug Gregor
d6dad48548 Simplify constraint application now that open-existentials are more local.
Remove some unnecessary boilerplate when working with ExprRewriter and
eliminate some closeExistential() call sites that are no longer
useful. NFC.

Swift SVN r27107
2015-04-07 23:22:06 +00:00
Doug Gregor
26ffdc7ace Kill the sequence number in OpenedExistential.
Because we're binding opened existentials early now, we no longer need
to be able to sort them to bind them late. NFC

Swift SVN r27106
2015-04-07 23:22:05 +00:00
Doug Gregor
595fb8c94f Introduce lvalue open-existential expressions and start using them.
Place OpenExistentialExprs for references to lvalue subscripts or properties
(in protocol extensions) via existentials just outside of the member
or subscript reference, rather than far outside the expression. This
gives us a tighter bound on the open-existential expressions without
introducing the post-pass I was threatening.

OpenExistentialExprs just outside of lvalue member/subscript are
themselves lvalues. Resurrect John's OpenOpaqueExistentialComponent to
handle the opening of a (materialized) existential lvalues as an
lvalue path component. This has the nice effect of codifying the
formal access rules for opened existentials as well as handling inout
on opened existentials appropriately.

Big thanks to John for talking through the model with me and leaving
dead code around for me to use.

Swift SVN r27105
2015-04-07 23:22:05 +00:00
Roman Levenstein
a762fb2b94 Teach bridgeFromObjectiveC to make use of the knownConditionallyBridgeFromObjectiveC/knownForceBridgeFromObjectiveC
If a conformance to _BridgedToObjectiveC is statically known, generate a more efficient code by using the newly introduced library functions for bridging casts.
This covers the cases arising from the source code, but does not cover any casts resulting from SIL optimizations. Those will be covered by the subsequent commit.

This change is to stay in CSApply for now. But the plan is to make the bridged casts optimization a guaranteed optimization. Once it is done, there is no need to lower the bridged casts in a special way inside Sema, because they all can be handled by the optimizer in a uniform way. This would apply to bridging of Error types too.

Swift SVN r27101
2015-04-07 22:53:56 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
82f634624c Handle uses of mutating methods of protocol extensions on existentials.
To properly deal with mutating methods on protocol extensions accessed through an existential (such as a property or subscript setter), open the existential as an lvalue so that its value can be mutated. 

As part of this, make sure we form any OpenExistentialExprs at the top level of the expression if we didn't manage to build them sooner. This is a fairly ad hoc approach that I am not happy with (these could probably be placed better with a post-pass), but the cost of opening too early is fairly minimal.

Swift SVN r27068
2015-04-07 06:01:19 +00:00
Doug Gregor
cdd5850707 Simplify the tracking of opened existentials in CSApply. NFC
Swift SVN r27065
2015-04-07 06:01:15 +00:00
Doug Gregor
7d6f2accd9 Improve use of properties/subscripts of protocol extensions via existentials.
Improves the placement of open-existential expressions when accessing
a property or subscript declared in a protocol extension. We need to
delay until the load occurs when the property/subscript has a usable
setter.

Swift SVN r27064
2015-04-07 06:01:14 +00:00
Joe Groff
66ae68bcc3 Sema: Allow ErrorType-conforming types to be explicitly coerced 'as NSError'.
Swift SVN r26993
2015-04-04 22:38:04 +00:00
Doug Gregor
f4d98da668 Support the use of members of protocol extensions on existential types.
To use members of protocol extensions on existential types, we
introduce an OpenExistentialExpr expression to open up the existential
type (into a local archetype) and perform the operations on that local
archetype.

Unlike with uses of initializers or dynamic-Self-producing
methods of protocols, which produce similar ASTs, we have the type
checker perform the "open" operation and then track it through
constraint application. This scheme is better (because it's more
direct), but it's still using a simplistic approach to deciding where
the actual OpenExistentialExpr goes that needs improvement.

Swift SVN r26964
2015-04-04 00:00:14 +00:00
Chris Lattner
8a07a85a91 Progress towards let/else:
- Implement SILGen for conditional multi-pattern PBD's.
 - Have the type checker check where clauses on PBDs.
 - Change the AST to represent complex if/let PBD's with
   composed PBDs instead of breaking them down. For example, 
   represent:
     if let x? = foo(), y? = bar() where x == y {
   as a single PBD in a StmtCondition instead of representing
   it as three entries in the condition.

The later change is good for AST/source fidelity as well as providing
a cheap way to exercise all the logic I'm building.



Swift SVN r26959
2015-04-03 22:46:34 +00:00
Chris Lattner
2e188bda20 Fix <rdar://problem/20365753> Bogus diagnostic "refutable pattern match can fail"
We do this by banning single-element tuple patterns with a label (in most cases).
We now produce:
x.swift:2:8: error: label is not allowed on single element tuple pattern
  let (responseObject: Int?) = f()
       ^
x.swift:2:7: note: remove the parentheses to make this a type annotation
  let (responseObject: Int?) = f()
      ^                    ~
                           
x.swift:2:8: note: remove the label to make this a tuple pattern
  let (responseObject: Int?) = f() 
       ^~~~~~~~~~~~~~~




Swift SVN r26898
2015-04-02 20:57:50 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Chris Lattner
f7fe8a5f4a Fix <rdar://problem/20392122> Destructuring tuple with labels doesn't work
This pushes tuple pattern labels forward:
  - Actually record them in TuplePatternElt.
  - Remove the tuple shuffle ban that prevents some cases
    (e.g. the one in the radar) of a tuple with labels being shuffled
    onto a tuple without labels.
  - Remove dead code enabled by removing the restriction.



Swift SVN r26852
2015-04-02 04:23:54 +00:00
John McCall
08d3460a19 Implement throw expressions. Untested.
Tests tomorrow for this and 'catch', I promise. :)

Swift SVN r26432
2015-03-23 08:10:15 +00:00
Jordan Rose
b6c5872889 Account for Optional<Void> in comparing function types for ABI compatibility.
Fixes a crash when the user uses such a type. (Which is probably a
mistake--they probably meant to make the whole closure optional--but
that's another issue.)

rdar://problem/20163908

Swift SVN r26274
2015-03-18 18:55:54 +00:00
Doug Gregor
1511d7a15a Start building conformances when requested in the AST.
Previously, we would require the type checker to be able to build a
conformance, which meant we would actually have to lie in the AST
about having a conformance (or crash; we did the form). Now, we can
form the conformance in the AST and it will be checked in the type
checker when needed. The intent here is to push conformance creation
into the conformance lookup table.

To get here, we had to stop relying on the broken, awful,
ASTContext-wide conformance "cache". A proper cache can come back once
the model is sorted out.

Swift SVN r26250
2015-03-18 04:31:22 +00:00
Argyrios Kyrtzidis
68bd67fc12 [Parse/AST] Introduce an AST node for editor placeholders in expression contexts.
If the placeholder is a typed one, parse its type string into a TypeRepr,
resolve it during typechecking and set it as the type for the associated EditorPlaceholderExpr.

Swift SVN r26215
2015-03-17 01:53:02 +00:00