Commit Graph

28382 Commits

Author SHA1 Message Date
Eli Friedman
f1ffa870a3 A few adjustments to AST/Sema for ConstructorDecls, and starting IRGen.
Swift SVN r2160
2012-06-06 00:53:44 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
f4c1884a55 Make misc error handling a bit more robust.
Swift SVN r2158
2012-06-05 21:32:24 +00:00
Doug Gregor
5996df1ad1 When substituting into the type of a protocol requirement to compare
it against potential witnesses, make sure to use the unlabeled form of
the substituted type. Otherwise, tuples with element names in the
return type will break us. Fixes <rdar://problem/11598297>.


Swift SVN r2156
2012-06-05 20:50:13 +00:00
Doug Gregor
0ca4d69ab5 When coercing an expression of tuple type that is *not* a TupleExpr to
another tuple type, we don't have a 'null' tuple shuffle because the
type changes. Fixes <rdar://problem/11591629>.


Swift SVN r2145
2012-06-04 23:49:48 +00:00
Doug Gregor
6d2eecfc94 When substituting a set of protocols for an archetype, if there is
only one protocol, just use that as the existential type rather than
unnecessarily wrapping it in protocol<>. This is just for simplicity.


Swift SVN r2140
2012-06-04 19:38:14 +00:00
Doug Gregor
81b45019e1 When building an archetype within a protocol, capture the list of
protocols it conforms to. Use this list when substituting into a
protocol's signature, so that we get an existential type back. For
example:

  var e : Enumerable
  var r = e.getElements()
  r.getFirstAndAdvance() // okay: r is a range.





Swift SVN r2139
2012-06-04 19:36:25 +00:00
Doug Gregor
3e55c1ae09 Switch the type-checking of the foreach loop over to the Enumerable
protocol, eliminating the last bits of the informal for-each
protocol. <rdar://problem/11475213>


Swift SVN r2137
2012-06-04 17:55:04 +00:00
Doug Gregor
1bf18a2472 Implement requirements on associated types (<rdar://problem/11548273>).
Swift SVN r2134
2012-06-04 16:43:40 +00:00
Doug Gregor
9abd2340bc Allow an 'inheritance' clause on typealiases, specifying what
protocols the underlying type of the type alias shall conform to. This
isn't super-motivating by itself (one could extend the underying type
instead), but serves as documentation, makes typealiases provide the
same syntax as other nominal types in this regard, and will also be
used to specify requirements on associated types.


Swift SVN r2133
2012-06-04 16:15:47 +00:00
Eli Friedman
d829b3c775 Unify the complete unqualified lookup logic in the UnqualifiedLookup class.
Swift SVN r2109
2012-06-01 23:26:58 +00:00
Eli Friedman
0e7ef8cebb Start refactoring code towards a single complete implementation of unqualified lookup.
Swift SVN r2108
2012-06-01 01:37:44 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Doug Gregor
1dc9b1597a Unbreak CMake build
Swift SVN r2104
2012-05-31 23:39:07 +00:00
Eli Friedman
29a13e9ae0 Move the NameLookup class into the AST library.
Swift SVN r2101
2012-05-31 22:35:50 +00:00
Eli Friedman
40156c1d70 Update CMake.
Swift SVN r2100
2012-05-31 22:27:55 +00:00
Eli Friedman
d61b7bf2a2 Move the REPL-specific type-checking code into its own file.
Swift SVN r2099
2012-05-31 22:27:25 +00:00
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +00:00
Eli Friedman
c404598fcb Parsing and semantic analysis for 'break' and 'continue'.
Swift SVN r2087
2012-05-31 00:55:33 +00:00
Doug Gregor
3c2fb97bdf Introduce TypeBase::isExistentialType(), to determine whether a given
type is either a protocol type or a protocol composition type. The
long form of this query returns the minimal set of protocol
declarations required by that existential type.

Use the new isExistentialType() everywhere that we previously checked
just for ProtocolType, implementing the appropriate rules. Among other
things, this includes:
  - Type coercion
  - Subtyping relationship
  - Checking of explicit protocol conformance
  - Member name lookup

Note the FIXME for IR generation; we need to decide how we want to
encode the witnesses for the different protocols.

This is most of <rdar://problem/11548207>.


Swift SVN r2086
2012-05-31 00:26:13 +00:00
Eli Friedman
6232341e48 Revert r2068. The AST is still wrong with that fix; it only suppresses the crash.
Swift SVN r2071
2012-05-30 18:11:24 +00:00
Chris Lattner
151e02046f fix the sema crash in rdar://11546285, which happens when CoerceExpr had an
unresolvable subexpression on the first pass.  There is still a irgen crash 
on the same testcase.


Swift SVN r2070
2012-05-30 17:14:42 +00:00
Doug Gregor
c079874625 Implement parsing, AST, type canonicalization, and type validation for
protocol conformance types, e.g., 'protocol<P, Q>'. A few things
people *might* want to scream about, or at least scrutinize:

  - The parsing of the '<' and '>' is odd, because '<' and '>' aren't
    tokens, but are part of the operator grammar. Neither are '>>',
    '>>>', '<>', etc., which also come up and need to be parsed
    here. Rather than turning anything starting with '<' or '>' into a
    different kind of token, I instead parse the initial '<' or '>'
    from an operator token and leave the rest of the token as the
    remaining operator.
  - The canonical form of a protocol-composition type is minimized by
    removing any protocols in the list that were inherited by other
    protocols in the list, then sorting it. If a singleton list is
    left, then the canonical type is simply that protocol type.
  - It's a little unfortunate that we now have two existential types
    in the system (ProtocolType and ProtocolCompositionType), because
    many places will have to check both. Once ProtocolCompositionTypes
    are working, we should consider whether it makes sense to remove
    ProtocolType.

Still to come: name lookup, coercions.



Swift SVN r2066
2012-05-30 00:39:08 +00:00
Eli Friedman
d836150359 Switch script mode over to a two-phase type-checking model, similar to what we use for libraries. I'm not entirely sure it's the right model, but it's close enough for the moment.
Swift SVN r2059
2012-05-29 21:57:44 +00:00
Chris Lattner
e16e37820d spacing fix.
Swift SVN r2014
2012-05-26 21:32:11 +00:00
Chris Lattner
5c15e2322f the fixme is already fixed by the new code, I just need to kill off the redundant logic.
Swift SVN r2012
2012-05-26 20:52:01 +00:00
Chris Lattner
1cd3220414 - Fix the diagnostic produced in visitUnresolvedMemberExpr to print the
oneof's type, not the type we're trying to infer.  This matches the diagnostic.
- Fix the diagnostic produced by visitUnresolvedMemberExpr when we find
  a non-function element but expect a function, to say so.
- Fix coercing in visitUnresolvedDotExpr to handle the case when we do infer a
  type for the result of the UnresolvedDotExpr.  Even though it isn't helpful, it
  isn't a bad thing to infer things :)
- Fix the logic that I added in an if(0) block to SemaCoerce::visitApplyExpr to
  preserve the "CF_Apply" bit.  Dropping this is bad.
- Move this logic around a bit and enable it!  This allows zapping some terrible
  "syntactic" processing of UnresolvedMemberExpr, and a fixme.

The terrible "syntactic" handling of OverloadSetRefExpr will die next.



Swift SVN r2011
2012-05-26 20:49:27 +00:00
Chris Lattner
a0fcd33ebd - Enhance SemaCoerce to work when DestTy is an unresolved type like "Unresolved -> Int".
It still doesn't work for fully unstructured unresolved types.

- Enhance contextual resolution of UnresolvedMemberExpr to handle types like Unresolved->SomeOneOf.

- Enhance overload set resolution to work with types like "Unresolved->SomeTy", though this
  implementation is seems dubious to me and ignores type information that we have about the argument
  type.  I'd like to require the argument to also be a subtype, but I need to teach isSubtypeOf about
  unresolved types.  I'd love review of this code from someone.

- Add an if(0)'d out blob of code (which is close but not completely right) that handles coercing
  of applys with structure inference instead of syntactic inference, which will ultimately zap a 
  bunch of code and some FIXMEs.



Swift SVN r2008
2012-05-26 06:08:37 +00:00
Chris Lattner
6dbf0721d4 add a helper function, fit to 80 cols
Swift SVN r2007
2012-05-26 06:04:24 +00:00
Eli Friedman
e63a471347 Fix value name-binding so it correctly performs member lookup for expressions which aren't inside a member function.
Swift SVN r2004
2012-05-25 23:42:40 +00:00
Eli Friedman
95838dca5d Move the SequenceExpr transformation from the expression pre-check into the main expression type-checking visitor.
Swift SVN r2002
2012-05-25 22:27:50 +00:00
Eli Friedman
2289b10a28 Slightly simplify the code for type-checking decls.
Swift SVN r2001
2012-05-25 22:03:59 +00:00
Eli Friedman
a75fdba660 Fix protocol checking so it happens in the right order. Fixes <rdar://problem/11515674> in -parse-as-library mode.
A refactor of the various visitors in DeclChecker in TypeCheckDecl.cpp is coming up next.



Swift SVN r2000
2012-05-25 21:55:32 +00:00
Eli Friedman
0b805c432c Simplify: TupleExprs can't have null elements.
Swift SVN r1985
2012-05-25 01:53:02 +00:00
Eli Friedman
6fe5759841 Get rid of a hack where ASTWalker was trying to walk the AST for BinaryExprs in a non-standard order. It introduces complexity with no obvious benefit.
Swift SVN r1984
2012-05-25 01:39:00 +00:00
Eli Friedman
bf41d390ca Reduce by one the number of times we walk the AST in type-checking.
Swift SVN r1983
2012-05-25 01:27:13 +00:00
Eli Friedman
d5cc517e43 Add default implementation for printing StructTypes to the REPL, which got temporarily removed with the StructDecl rewrite.
Swift SVN r1982
2012-05-25 00:50:20 +00:00
Doug Gregor
e56d5ed125 Don't attempt to coerce a literal directly to an existential
type. Instead, coerce to the appropriate default literal type and then
coerce from there to the existential type.


Swift SVN r1964
2012-05-23 23:42:39 +00:00
Doug Gregor
0062c84351 Introduce ExistentialMemberRefExpr for references to the members of
values of existential type, e.g.,

  var x : Printable
  x.print()

Existential member references reify the type of the implicit object
argument (implicitly, because we have no way of expressing this in the
type system), and replace the types of any other archetypes
with existential types that (don't, but will eventually) conform to
the protocols to which the archetypes conform.



Swift SVN r1963
2012-05-23 23:06:34 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
eb3c93b4a9 Switch the implementation of the for-each loop over to the formal
Range protocol, rather than using an informal protocol. This is most
of <rdar://problem/11475213>, although we still use an informal
protocol for the initial 'getElements()' call because we don't yet
have the ability to add requirements to associated types.



Swift SVN r1961
2012-05-23 17:47:50 +00:00
Doug Gregor
179c7c1b24 Make explicit protocol conformance checking more robust against
unsatisfied associated type requirements. Otherwise, we would assert
because substitution did not have a binding for the unsatisfied
archetypes. This whole conforms-to matching stuff will eventually be
rewritten, so it doesn't bother me that we don't continue checking
very far after failing to satisfy an associated type requirement.


Swift SVN r1958
2012-05-23 16:33:56 +00:00
Doug Gregor
39c2c90c8b Loosen type checking for protocol conformance slightly, by comparing
the unlabeled types rather than labeled types. It's ridiculous to
require the same parameter names (although one could perhaps use them
as a tie-breaker).


Swift SVN r1956
2012-05-23 15:30:22 +00:00
Doug Gregor
7f3b2ed843 Drop default arguments in tuples during substitution, rather than carrying them on in a potentially-broken state.
Swift SVN r1955
2012-05-23 15:28:18 +00:00
Doug Gregor
74436a3120 Introduce the implicit 'This' type into protocols, which refers to the
type T that conforms to the given protocol. 'This' is modeled simply
as an associated type.



Swift SVN r1953
2012-05-23 14:45:55 +00:00
Eli Friedman
3d11eebb69 Make sure we delay type-checking for default values in tuples if the tuple specifies the type of a global.
Swift SVN r1949
2012-05-23 01:57:07 +00:00
Eli Friedman
cb45b45515 Make type-checking for decls aware of the multi-pass semantics of the global scope for libraries. No functional change.
Swift SVN r1948
2012-05-23 01:28:48 +00:00
Eli Friedman
377972b1ba Start shuffling around code for name binding on values; with the proposed shadowing rules, we need to delay name binding on values until after some parts of type-checking.
Swift SVN r1946
2012-05-23 00:42:53 +00:00
Doug Gregor
8e1cd3990b Implement substitution of types, which substitutes concrete types for
archetypes. Use this substitution when checking the
variable/function/subscript witnesses during protocol conformance.

This allows us to check the conforms-to relationship for the Range
protocol as we want to express it.


Swift SVN r1945
2012-05-23 00:39:06 +00:00
Eli Friedman
360f48f3c7 Fix a bug with varargs pointed out by Howard.
Swift SVN r1944
2012-05-23 00:31:16 +00:00