Commit Graph

28382 Commits

Author SHA1 Message Date
Doug Gregor
d37602629e Implement parsing, AST, and conformance checking for associated types
in protocols, e.g.,

  protocol Range {
    typealias Element
    func getAndAdvance() -> Element
  }



Swift SVN r1941
2012-05-22 21:45:58 +00:00
Doug Gregor
9552aa5e10 Implement basic support for refering to a nested type within
unqualified lookup, based on context. For example:

struct String {
  struct CharRange { /* ... */ }
  
  func getElements() -> CharRange {
    return CharRange(value)
  }
}




Swift SVN r1939
2012-05-22 21:08:22 +00:00
Doug Gregor
2b7d77aecd Remove an assert that will fire on invalid code (e.g., when one of
these types ends up being an error type).


Swift SVN r1938
2012-05-22 21:00:59 +00:00
Eli Friedman
bce8a7a8dc When ValidateType fails on a type, don't keep it around in the AST.
Swift SVN r1927
2012-05-22 01:17:27 +00:00
Eli Friedman
3ff2ef1efb Allow the verifier to perform partial checking if there's an error in type-checking.
Swift SVN r1925
2012-05-22 00:34:12 +00:00
Doug Gregor
c68c9da1b6 Introduce ThisApplyExpr, an ApplyExpr meant for the various forms of
application expressions that provide a 'this' parameter to a
method. There will eventually be more than just DotSyntaxCallExpr, to
capture the other syntactic (and implicit) forms.


Swift SVN r1924
2012-05-22 00:25:40 +00:00
Doug Gregor
b1f1e1430d Introduce NominalType as a base class of
OneOfType/StructType/ClassType/ProtocolType, an eliminate the
ridiculous chained ifs that used to check for most (or all) of these.


Swift SVN r1923
2012-05-22 00:13:59 +00:00
Doug Gregor
58146b4cea Zap a no-longer-relevant FIXME
Swift SVN r1922
2012-05-21 23:40:43 +00:00
Doug Gregor
a9906ad38f Introduce support for implicit user-defined conversions.
A user-defined conversion function is an instance method that accepts
an empty tuple and returns a value of the type we're converting to,
has the [conversion] attribute, and is named __conversion. The last of
these restrictions is a temporary hack to work around our inability to
perform a lookup across all extensions for "every function with the
conversion attribute", and shouldn't last too long.

As in C++, we only get one user-defined conversion function. Unlike in
C++, a constructor is not (and cannot) be a conversion function.

Introduce NSString <-> String conversion functions, but leave the
runtime implementations as stubs for Dave to fill in.



Swift SVN r1921
2012-05-21 23:36:16 +00:00
Eli Friedman
bdaa76ad42 Extend the list of types we can use to lookup T[] -> SliceT.
Swift SVN r1903
2012-05-19 00:26:11 +00:00
John McCall
38bac7c706 Add Builtin.ObjCPointer with accompanying IR-gen support and
wrap it in an 'id' type in the standard library.

Also fix a bug noticed by inspection where initWithTake for
function types wasn't entering a cleanup for the taken value.
This probably doesn't matter for existing possibilities, but
it's potentially important under exceptions.

Swift SVN r1902
2012-05-18 23:40:17 +00:00
John McCall
71c45f5212 Lion's libc++ headers do not support shared_ptr under -fno-rtti.
This is <rdar://problem/10217868>.  Apparently I'm using Lion's
libc++ headers somehow, which I should probably fix;  but since
the use of shared_ptr is just a hack until DenseMap supports
move-only types, I don't feel bad about changing it to a different
hack that avoids shared_map altogether.

Swift SVN r1897
2012-05-18 10:01:54 +00:00
Eli Friedman
bb0a98d487 Finish off varargs.
Swift SVN r1892
2012-05-18 00:04:07 +00:00
Doug Gregor
c3812691dc Detect circular protocol inheritance with a cleaner diagnostic.
Swift SVN r1888
2012-05-17 17:05:09 +00:00
Doug Gregor
53cc4c7049 Only oneofs, structs, and classes can be extended. Check this.
Swift SVN r1887
2012-05-17 15:59:21 +00:00
Doug Gregor
f6f5b690b0 Semantic analysis for inheritance clauses, which checks for protocol
conformance explicitly.


Swift SVN r1886
2012-05-17 15:45:16 +00:00
Eli Friedman
d4750d9014 Finish off the semantic analysis of vararg tuples.
Swift SVN r1880
2012-05-17 01:44:27 +00:00
Eli Friedman
7614b53e9f Semantic analysis, part 1b.
Swift SVN r1878
2012-05-17 00:58:53 +00:00
Eli Friedman
8fc8d4cdf7 Semantic analysis for varargs, part 1.
Swift SVN r1877
2012-05-17 00:52:38 +00:00
Eli Friedman
80dba01ae4 Simplify tuple coercion code. No functional change intended.
Swift SVN r1876
2012-05-16 23:04:30 +00:00
Eli Friedman
33f20a14e0 Add NewReferenceExpr, for allocating class objects.
Swift SVN r1867
2012-05-16 01:36:03 +00:00
Eli Friedman
98933b8510 More work on ClassDecls; this is enough to get member access working.
Swift SVN r1863
2012-05-16 00:22:09 +00:00
Eli Friedman
79c3276b07 AST representation for ClassDecls.
Swift SVN r1858
2012-05-15 21:53:38 +00:00
Eli Friedman
6f045aad2f Throw the switch to use "var" syntax to declare members of structs. This also means we no longer build an implicit extension for every struct decl. Everything seems to be working, but please yell if this breaks anything.
Swift SVN r1851
2012-05-15 03:27:13 +00:00
Eli Friedman
d97a422008 Switch isLiteralCompatibleType over to use MemberLookup rather than performing a lookup directly.
Swift SVN r1850
2012-05-15 02:26:01 +00:00
Eli Friedman
4a18a1ca26 Restore a FIXME I accidentally dropped.
Swift SVN r1849
2012-05-15 02:21:18 +00:00
Eli Friedman
87dd43a4b8 Refactor member and constructor lookup to depend on centralized routines in Module rather than scattering assumptions about how lookup works across Sema. This should make it easier to make changes in the future which affect lookup.
I'm not entirely sure these are the right APIs to expose, but this at least seems like progress.



Swift SVN r1848
2012-05-15 02:04:53 +00:00
Doug Gregor
bf03c9af28 Remove byref(implicit). Instead, introduce [assignment], which only
applies to operators whose first parameter is [byref]. Assignments
must return Void, and have their first arguments implicitly treated as
an lvalue.

As part of this, add the various C compound operators (+=, -=, *=, /=,
&=, |=, and ^=) to the standard library.



Swift SVN r1846
2012-05-15 00:55:32 +00:00
Eli Friedman
907cc521ab Switch a couple booleans in Module over to an enum.
Swift SVN r1845
2012-05-15 00:20:01 +00:00
Eli Friedman
f9c3264ec9 Fix a minor bug in type-checking with library-style parsing.
Swift SVN r1843
2012-05-14 22:45:14 +00:00
Eli Friedman
f945f3c75b Simplify type-checking for FuncDecls.
Swift SVN r1842
2012-05-14 22:28:59 +00:00
Doug Gregor
5b25e63abb Don't allow materialization with byref(implicit).
Swift SVN r1841
2012-05-14 22:20:01 +00:00
Dave Zarzycki
8ca12ef319 Fix missing newline at EOF
Swift SVN r1840
2012-05-14 19:19:31 +00:00
Doug Gregor
056ba286eb Implement subtyping rules that allow one to convert a function type to
another function type, so long as the source is a subtype of the
target. The subtyping relation is fairly obvious, allowing parameter
renaming, qualification conversions for lvalue types, and
protocol-conformance conversions (at the top level of function
types). It is a strict subset of the allowed type coercions.

The representation of FunctionConversionExpr is temporary. It will
need to account for the capture of the source of the conversion in the
trivial-trivial case.



Swift SVN r1839
2012-05-14 19:10:22 +00:00
Doug Gregor
59db25658a Ban the use of SuperConversionExpr to produce lvalues, since that is,
in general, not sound. For the limited cases where we did use this
expression kind on lvalues (member access or instance method
invocations on a superprotocol), leave the conversion to the client of
their respective AST nodes (MemberRefExpr, DotSyntaxCallExpr). We may
decide to enrich these ASTs in the future with more information about
the conversion path, but it's not clear that it's actually useful
information for, e.g., IRgen.


Swift SVN r1830
2012-05-14 15:38:27 +00:00
Eli Friedman
df9156589b Ban default values in patterns in semantic analysis. Null out default values from patterns for function signatures, since default values are really part of the type, not the pattern, in that case. Fixes <rdar://problem/11406484>.
Swift SVN r1821
2012-05-12 01:53:37 +00:00
Doug Gregor
ec674b3bce Make the implicit 'this' argument [byref] rather than
[byref(implicit)], and rely on type coercion for the implicit object
argument to deal with the implicitness. This is one half of
<rdar://problem/11215969>. 

The other half of <rdar://problem/11215969> requires us to invent some
syntax to allow increment/decrement/assignment to operate on lvalues
without requiring one to write '&'. There are two distinct ideas
gaining traction here:

  - Adding an [assignment] attribute to these operators, which tells
    us both that use of the operators is a statement (not an
    expression) and that the byref argument (either on the left, or
    the only argument).

  - Allowing operators to be written as member functions, so that they
    get the same treatment as "a.b".

The former seems like the better option.



Swift SVN r1819
2012-05-12 00:19:22 +00:00
Eli Friedman
5ac790e0e9 Fix member name lookup so the logic is clearer, and so we don't end up with strange results for lookups into metatypes.
Swift SVN r1818
2012-05-11 23:30:55 +00:00
Doug Gregor
a49d6c88c8 Introduce a conversion-to-supertype expression to capture conversions
from a protocol to a protocol it inherits. This is a far simpler
operation that the general type-erasure expression, so generate this
AST when we can.


Swift SVN r1813
2012-05-11 17:25:14 +00:00
Doug Gregor
2b11e0c327 Add a type coercion flag that indicates when we are performing the
conversion for the implicit argument of a method ('this'), along with
an entry point (coerceObjectArgument) to perform type coercion of the
object argument to an lvalue. Use this entry point for member
reference expressions (that refer to variables/properties) and method
calls. This is a step toward eliminating [byref(implicit)] on the
implicit 'this' parameter.

More immediately, use this to close up the giant type-safety loophole
I introduced yesterday regarding conversions to references of protocol
type.



Swift SVN r1812
2012-05-11 16:55:14 +00:00
Doug Gregor
de42680a47 Switch the boolean 'Apply' in the type-coercion code to a set of
flags, with just one flag at this point (CF_Apply). No functionality
change.


Swift SVN r1810
2012-05-11 15:23:05 +00:00
Eli Friedman
01a18f6c7a Use VarDecls to represent struct members, and MemberRefExprs to represent member access in structs. Eliminate the horrible hack which was LookThroughOneOfExpr.
Swift SVN r1808
2012-05-11 03:08:15 +00:00
Doug Gregor
755f789aa0 Diagnose attempts to inherit from a non-protocol type.
Swift SVN r1806
2012-05-11 00:31:26 +00:00
Doug Gregor
09ef9525fa Only create erasure expressions in two places: one for lvalues and one
for rvalues.


Swift SVN r1805
2012-05-11 00:24:23 +00:00
Doug Gregor
70bfc235b8 Implement protocol inheritance, e.g.,
protocol Document { var title : String }
  protocol Versioning { func bumpVersion() }
  protocol VersionedDocument : Document, Versioning { }

This commit covers the basic functionality of protocol inheritance, including:
  - Parsing & AST representation
  - Conforming to a protocol also requires conforming to its inherited
  protocols
  - Member lookup into a protocol also looks into its inherited
  protocols (results are aggregated; there is no name hiding)
  - Teach ErasureExpr to maintain lvalueness, so we don't end up
  performing a silly load/erase/materialize dance when accessing
  members from an inherited protocol.




Swift SVN r1804
2012-05-11 00:00:50 +00:00
Eli Friedman
05fe3c907f Propagate a DeclContext through NameBinding for IdentifierTypes.
Swift SVN r1803
2012-05-10 23:34:01 +00:00
Doug Gregor
3e7b52d025 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.



Swift SVN r1797
2012-05-10 18:55:30 +00:00
Doug Gregor
88b214d020 Revert r1792; it's missing a file :(
Swift SVN r1795
2012-05-10 17:13:44 +00:00
Doug Gregor
f4f2f9f570 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.


Swift SVN r1794
2012-05-10 16:15:34 +00:00
Chris Lattner
a5030c00cb minor pedantic tidying up.
Swift SVN r1783
2012-05-09 00:53:46 +00:00