Commit Graph

2038 Commits

Author SHA1 Message Date
Chris Lattner
09705dc7cd 1) Redesign DeclAttributes to be based around an array indexed by attribute, instead
of having a ton of ad-hoc bools in it.  This allows us to consolidate a ton of 
   boilerplate, eliminating 250 lines of code:

 17 files changed, 435 insertions(+), 662 deletions(-)

2) This eliminates the special case for weak and unowned attributes, which previously
   didn't show up in Attr.def.

3) While we're at it, keep track of proper source locations for each attribute, and
   use these to emit diagnostics pointing at the attribute in question instead of at
   a funcdecl or the @ sign.

4) Fix axle attributes, which had vertex and fragment swapped.



Swift SVN r9263
2013-10-13 01:25:50 +00:00
Dmitri Hrybenko
89a8cddbe0 AST Printer: add PrintOptions::SynthesizeSugarOnTypes for use by LLDB in some
cases


Swift SVN r9248
2013-10-12 00:43:32 +00:00
Dmitri Hrybenko
2acfadb38d AST printer: correctly print more complex cases of variadic tuple patterns
Swift SVN r9236
2013-10-11 23:47:07 +00:00
John McCall
af706c889a swift::SILFunctionType::ParameterType -> swift::SILParameterInfo
swift::SILFunctionType::ReturnType -> swift::SILReturnInfo

Swift SVN r9116
2013-10-10 00:31:38 +00:00
Doug Gregor
7fee09b41e Axle: Implement Matrix<T, N> and Matrix<T, N, M> syntactic sugar.
This completes the majority of <rdar://problem/15100137>.


Swift SVN r9098
2013-10-09 22:24:21 +00:00
Dmitri Hrybenko
6ad6518a56 AST Printer: prefer visit() to nested print() calls
Swift SVN r9093
2013-10-09 21:38:46 +00:00
Doug Gregor
fba128e191 Axle: Implement Vec<T, N> syntactic sugar for the VecTxN structs.
Implements the first part of <rdar://problem/15100137>.


Swift SVN r9092
2013-10-09 21:12:19 +00:00
John McCall
a38abec9fe Introduce (but don't yet use) SILFunctionType.
Swift SVN r9088
2013-10-09 20:55:42 +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
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
b884b17891 AST Printer: don't print a space before a colon in a tuple label
For example:

  func f(a: Int)

instead of:

  func f(a : Int)


Swift SVN r8795
2013-09-30 22:58:16 +00:00
Joe Groff
92cce69e15 AST: Give NominalTypePattern a better AST-level representation.
Instead of relying on the subpattern being a well-formed TuplePattern, let's track our own subelements so we can associate them to properties and validate them ourselves.

Swift SVN r8771
2013-09-30 01:03:18 +00:00
Dmitri Hrybenko
52555294f9 Type printer: replace a broken variant of GenericParamList printer with a use of AST printer
Swift SVN r8751
2013-09-28 02:45:44 +00:00
Dmitri Hrybenko
38994060d5 AST printing: merge swift::Type::PrintOptions into swift::PrintOptions
There is no reason to have two different options structs.


Swift SVN r8749
2013-09-28 02:19:31 +00:00
Dmitri Hrybenko
b33caadd89 AST printer: print raw type of EnumDecl
Swift SVN r8716
2013-09-27 01:52:07 +00:00
Dmitri Hrybenko
448d7cff8e AST Printer: add tests for printing deserialized modules
...and fix bugs found by this.


Swift SVN r8706
2013-09-26 23:17:32 +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
Dmitri Hrybenko
5c142346c6 Destructor syntax: require an empty parameter list for destructors
rdar://14968738


Swift SVN r8694
2013-09-26 18:09:12 +00:00
Dmitri Hrybenko
5268940301 AST Printer: simplify the check for DynamicLookup known protocol
Swift SVN r8677
2013-09-25 23:41:33 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Anna Zaks
970bcd3bc6 fixup for r8625
Fix a copy and paste error + a better comment.
Thanks Dmitry.

Swift SVN r8631
2013-09-25 17:56:23 +00:00
Anna Zaks
30039a59f1 Emit Swift declarations when printing SIL.
Only print function member declarations and skip the bodies since the bodies are already represented in SIL and ASTPrinter is not good enough to print arbitrary expressions.

In order to have valid output, make sure that ASTPrinter does not print references to DynamicLookup protocol.

Swift SVN r8627
2013-09-25 17:08:42 +00:00
Dmitri Hrybenko
725b0e01eb AST Printer: fix printing of same type requirement in generic parameter lists
These types are really the same for the type checker, so they are printed in
exactly the same way.  To recover the original spelling, prefer to print
a TypeRepr, if available.


Swift SVN r8603
2013-09-24 21:16:35 +00:00
Dmitri Hrybenko
71dddd1c88 AST Printer: implement requirement printing in a generic parameter list
Swift SVN r8595
2013-09-24 17:55:19 +00:00
Dmitri Hrybenko
a044e2a420 AST Printer: don't print properties twice and don't print top-level variables in braces
Swift SVN r8587
2013-09-24 02:05:02 +00:00
Dmitri Hrybenko
dec19cc7c3 AST printing: function parameter printing: simplify code
Swift SVN r8585
2013-09-24 01:27:13 +00:00
Dmitri Hrybenko
10d8fdc64f AST/AbstractFunctionDecl: Remember if a function had a selector-style signature
... and use this information in AST printing


Swift SVN r8583
2013-09-24 00:56:33 +00:00
Dmitri Hrybenko
c9d1aa3f96 AST Printer: fix parameter name printing in setters
Also, add an AST verifier check that the parameter patterns in getters/setters
are sane.


Swift SVN r8574
2013-09-23 22:25:35 +00:00
Dmitri Hrybenko
ec899dee8c AST Printer: don't print a trailing space after "get:", "set:" labels
Swift SVN r8566
2013-09-23 20:12:04 +00:00
Dmitri Hrybenko
af8fa8c8cd Remove a circular dependency AST<->Sema caused by type printing
AST used to depend on Sema in type printing.  Specifically,
TypeVariableType::printImpl() is inside Sema.

This change moves the type variable identifier from
TypeVariableType::Implementation to TypeVariableType. This enables us to print
type variables in AST library.

Because type variable type is a temporary type for use inside type checker
only, I don't expect that we will modify it to be more verbose to enhance
diagnostics.  This is a job for locator printing.


Swift SVN r8559
2013-09-23 17:40:43 +00:00
Dmitri Hrybenko
efd8e75647 Move type printing to ASTPrinter.cpp and use the AttributePrinter class in Decl attribute printing
Swift SVN r8543
2013-09-21 04:09:28 +00:00
Joe Groff
f9480828e0 Remove EnumCaseDecl backreference from EnumElementDecl.
Swift SVN r8516
2013-09-20 20:50:24 +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
Doug Gregor
bc3f655105 s/constructor/init in a few more places.
Swift SVN r8504
2013-09-20 18:37:15 +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
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
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
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Jordan Rose
3107bcd8bb AST printer: include inheritance info even if we don't have source info for it
Essentially, fall back to the list of protocols (and possibly the superclass)
if the "inherited types" array is empty.

<rdar://problem/14788337>

Swift SVN r7884
2013-09-04 00:31:32 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Chris Lattner
69d0afb658 rename [force_inlining] to [transparent].
Swift SVN r7448
2013-08-22 16:05:41 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Jordan Rose
26c1181502 Fix printing for unions, vars, subscripts, and typealiases.
Union cases were still being printed enum-style, and computed vars,
subscripts, and typealiases would print their definitions even when
the corresponding printing option was disabled. All fixed.

Swift SVN r7285
2013-08-16 20:21:55 +00:00
Doug Gregor
ad71b469bc When pretty-printing func declarations, use selector style when needed.
Swift SVN r7284
2013-08-16 18:45:04 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Jordan Rose
093a428ca9 Add parsing support for the [exported] attribute.
As discussed, this is an interim syntax for re-exports:
  import [exported] Foundation
In the long run, we're probably going to use the same syntax as access
control for this, but that hasn't been designed yet.

Swift SVN r7050
2013-08-08 19:09:10 +00:00
Jordan Rose
c92fa28833 Have ImportDecl vend a separate "module path" and "decl path".
This makes it very clean to reason about which part should be used
to find a module to load, and which part should be used to filter
lookup within that module.

This breaks the old "import swift.print" syntax in favor of the new
"import func swift.print", but the new syntax is currently ignored.

Swift SVN r6849
2013-08-02 21:00:22 +00:00