Commit Graph

3461 Commits

Author SHA1 Message Date
Doug Gregor
77264dc10f Give associated type declarations interface types.
This required moving a gross hack from the old archetype-based
type-opening code over to the new, generic type parameter-based
type-opening code. We need the ability to build conformances for types
involving type variables to address this case properly.


Swift SVN r9821
2013-10-30 22:53:28 +00:00
Argyrios Kyrtzidis
e31c93add3 [AST] The ASTContext parameter in FuncDecl::getResultType() is not really needed.
Swift SVN r9798
2013-10-30 17:09:56 +00:00
Dmitri Hrybenko
8218c411ff Don't cache the result of ProtocolDecl::requiresClass() if the type checker did
not calculate the inherited protocols yet


Swift SVN r9774
2013-10-30 00:34:23 +00:00
Doug Gregor
a7664fda78 Clean up the checking of pattern binding declarations.
Eliminate the annoying, rarely-firing "while converting 'var' initial
value to declared type" note. We'll eventually have better ways to
deal with this. Otherwise, no functionality change.


Swift SVN r9677
2013-10-25 21:14:03 +00:00
Argyrios Kyrtzidis
549dfb882a [AST] Record and report the protocol requirement decls that a ValueDecl conforms to.
Swift SVN r9587
2013-10-22 15:47:37 +00:00
Doug Gregor
cd0299f85a Push get/setInterfaceType() up to ValueDecl.
No functionality change here.


Swift SVN r9552
2013-10-21 19:05:02 +00:00
Doug Gregor
e3ebb03c28 Start opening GenericFunctionTypes for references to non-member functions.
When the type checker sees a reference to a generic non-member
function, open its interface type, which is expressed as a
GenericFunctionType, rather than its PolymorphicFunctionType. This is
a tiny step toward weaning the type checker off archetypes within the
interface.




Swift SVN r9504
2013-10-18 23:04:16 +00:00
Joe Groff
5721bdda01 Don't pretend we can parse enum case refined types.
There's no way we'll be able to fully implement GADTs anytime soon.

Swift SVN r9477
2013-10-18 01:34:25 +00:00
Jordan Rose
55d4d05b23 Don't automatically create one SourceFile for every TranslationUnit.
Many places are still relying on having one, though.

Swift SVN r9077
2013-10-09 18:38:26 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Doug Gregor
abeaef8996 Track the generic parameters and requirements of nominal type declarations.
Put generic nominal type declarations through the same dependent-type
validation as generic functions, then capture their generic parameters
and requirements in their generic signature. This allows us to
re-instate the requirements in their dependent forms, before the
archetypes ruin them completely.


Swift SVN r8958
2013-10-07 16:21:25 +00:00
Doug Gregor
91173c903d Handle 'self' and nested generics in the interface type of generic functions.
When building the (dependent) interface type of generic functions,
don't resolve any generic parameter types to archetypes, even those at
outer levels. Instead, keep everything dependent.

As a special case, the type of 'self' gets baked into the parameter
patterns with archetypes, so reconstruct the 'self' type ourselves.

The actual output of this is still frustratingly untestable, but we
get decent coverage because all of the type checking of generic
functions goes through here first.



Swift SVN r8936
2013-10-04 23:07:51 +00:00
Joe Groff
0d8d756c83 Sema: Teach conformance checking to derive requirements if needed.
For derivable protocols, such as RawRepresentable on raw-typed enums, when checking the conformance, create a conforming decl if an explicit decl wasn't found. Refactor the conformance derivation for toRaw/fromRaw to be driven by conformance checking in this way.

Swift SVN r8930
2013-10-04 20:50:43 +00:00
Doug Gregor
361447021c Canonicalize generic type parameters with depth/index.
Swift SVN r8893
2013-10-03 22:33:22 +00:00
Doug Gregor
12e228c0f1 Introduce a new representation of polymorphic function types.
Introduces a new kind of function type, GenericFunctionType, that
represents a polymorphic function type with all of its generic
parameters and requirements stored in a more readily canonicalizable
form. It is meant to eventually replace PolymorphicFunctionType, but
for now we build it up in parallel so we can switch over to it
pieacemeal.

Note: this representation is built and then thrown away. We'll start
recording it soon.


Swift SVN r8881
2013-10-03 17:59:35 +00:00
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +00:00
Argyrios Kyrtzidis
3d7cf2072d [AST] If a ValueDecl is given an error type, also make it invalid.
Swift SVN r8760
2013-09-29 00:12:17 +00:00
Argyrios Kyrtzidis
6942646f80 [AST] Make 'self' vars implicit and provide a source location for them.
Verifier expects all decls to have locations, let's keep it happy.

Swift SVN r8757
2013-09-29 00:12:13 +00:00
Dmitri Hrybenko
09f44aec2b Move ValueDecl::getDefaultArg() -> AbstractFunctionDecl::getDefaultArg()
Swift SVN r8744
2013-09-27 22:27:12 +00:00
Anna Zaks
3e5c1f81d2 Support transparent attributes on struct and enum extensions.
Attribute [transparent] on extensions should apply to all members(functions, properties) of that extension.

Addresses radar://15035271.

Swift SVN r8735
2013-09-27 20:29:31 +00:00
Dmitri Hrybenko
ba2e4732d0 Remove unused member EnumDecl::isEnum
Swift SVN r8710
2013-09-27 00:22:39 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Doug Gregor
cc4c7d0fd8 [Clang importer] Stop creating property/subscript getter/setter thunks.
Instead of synthesizing Swift code for the property and subscript
getters and setters we import from Objective-C, just create the
declarations and mark them as being Objective-C (foreign) entry
points. This means that we'll use the Objective-C entry points (via
objc_msgSend).


Swift SVN r8692
2013-09-26 15:58:19 +00:00
Anna Zaks
c2adc1e35b Restructure parsing to ensure that bodiless constructors/destructors/subscripts are fully diagnosed.
Previously, we followed an early exit for bodiless constructors/destructors/subscripts.
This prevented some diagnostics and full AST class setup in SIL parsing mode and for bodiless subscripts in general.

Thanks for the suggestion Dmitry!

Swift SVN r8672
2013-09-25 23:28:52 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Argyrios Kyrtzidis
e224667315 Refactor Implicit'ness of expressions.
Introduce a bit in Expr to indicate whether the expression is implicit and decouple the implicitness
of an expression from whether it has a source location or not.

This allows implicit expressions to be able to point at the source location where they originated from.
It also allows decoupling the implicitness of a parent from its children, so for example, an implicit CallExpr
can have an explicit parameter value.

Swift SVN r8600
2013-09-24 20:42:29 +00:00
Doug Gregor
6a1db609e0 Allow [objc] subscripts and emit Objective-C thunks for the getters/setters.
Sema and SILGen; IRGen to follow.


Swift SVN r8589
2013-09-24 02:26:23 +00:00
Joe Groff
c4b4db732f Parse and check raw values on enum cases.
Iff an enum declares a raw type, its cases may declare raw values or else have them assigned to them implicitly by autoincrementing from zero, like in C. If the raw type is float-, string-, or char-literal-convertible, there is no autoincrement, and the raw values must all be explicit. The raw type is rejected if any cases have payloads.

We don't yet diagnose duplicate raw values. That'll come next. We also don't yet serialize or deserialize the raw values. We don't strictly need to do this, since the RawRepresentable protocol conformance will be exported from the module as API, but Jordan pointed out that, for fragile raw values, this would be good for documents/jump-to-definition purposes, so we have a plan for only serializing the literals without having to deal with fully general expression serialization.

Swift SVN r8545
2013-09-21 04:31:26 +00:00
Joe Groff
7d35db8a73 Type-check raw type of enum decls.
Allow the inheritance clauses of enums to reference a non-protocol type as their raw type. For now, only diagnose that the raw type occurs first, that there's only one raw type, that there are no circularities in raw types, like we do for class inheritance, and additionally that the raw type is literal convertible, which we'll require for the raw values of the cases.

Swift SVN r8529
2013-09-20 23:13:07 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Chris Lattner
401ff53e70 fix bug that clang noticed:
Decl.cpp:997:59: warning: if statement has empty body [-Wempty-body]
      if (!firstPattern->getType()->isEqual(emptyTupleTy));
                                                          ^



Swift SVN r8388
2013-09-18 04:15:34 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Argyrios Kyrtzidis
f34166c319 [AST] For SubscriptDecl and ConstructorDecl, have the getLoc() point at the 'subscript'/'constructor' respectively, not at their first parameter.
Swift SVN r8346
2013-09-17 19:52:13 +00:00
Argyrios Kyrtzidis
420cab9bc3 [AST] Move the NameLoc source location from ValueDecl's subclasses into ValueDecl itself.
Swift SVN r8332
2013-09-17 15:34:52 +00:00
Doug Gregor
25bec36f9e Allow dynamic lookup through DynamicLookup.metatype.
Given an object of type DynamicLookup.metatype, allow us to find both
static and instance methods. 

Sema only; SILGen and IRGen changes to come.


Swift SVN r8290
2013-09-16 20:26:02 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Dmitri Hrybenko
5ac875e5dc Add CaptureInfo class that manages capture lists
Swift SVN r8234
2013-09-14 00:22:44 +00:00
Doug Gregor
8d3871098f Fix more vector-stream-flushing issues with extracting Objective-C selectors.
Swift SVN r8200
2013-09-13 16:44:52 +00:00
Doug Gregor
dee0a0491e Property return the string for a zero-argument selector.
Swift SVN r8199
2013-09-13 16:44:05 +00:00
Dmitri Hrybenko
ea75b2ac5f Fix implementation of ValueDecl::isDefinition()
No testcase because this is not testable now -- this function is only used in
diagnostics of value redefinitions, which are broken now for redefinitions of
member functions.


Swift SVN r8187
2013-09-13 03:49:07 +00:00
Dmitri Hrybenko
16ce358562 Sink FuncDecl::getExtensionType() to AbstractFunctionDecl
Swift SVN r8184
2013-09-13 02:57:09 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
8db6568394 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
(Recommit a complete refactoring.)


Swift SVN r8161
2013-09-12 21:01:52 +00:00
Dmitri Hrybenko
9e889d1b56 Revert my commit r8157. It is breaking tests in +Asserts.
Swift SVN r8160
2013-09-12 20:53:00 +00:00
Dmitri Hrybenko
f49f9b0774 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
Swift SVN r8159
2013-09-12 20:44:28 +00:00
Dmitri Hrybenko
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +00:00
Dmitri Hrybenko
796eac4b3f Make SILLocation::dump() more informative
Swift SVN r8130
2013-09-12 00:25:32 +00:00
Dmitri Hrybenko
3fb2d14a8e Simplify FuncDecl::getExtensionType() implementation
Replace it with a call to DeclContext::getDeclaredTypeInContext().


Swift SVN r8105
2013-09-11 20:52:52 +00:00