Commit Graph

1293 Commits

Author SHA1 Message Date
Joe Groff
1f7192f7f2 Add print/dump methods to Substitution.
Swift SVN r9512
2013-10-19 00:21:54 +00:00
Dmitri Hrybenko
011284e9c9 Make minus sign part of IntegerLiteralExpr and make integers literals 136-bits
wide

Currently integer literals are 64-bit.  In order to allow checking for overflow
while converting an integer literal to swift.UInt/Int* types we need at least
65 bits.  But floating point numbers (Float32, Float64, Float80) are
BuiltinIntegerLiteralConvertible.  In order to allow spelling large floating
point constants, we allow 136-bit literals.

Rationale: 128 bits are enough to represent the absolute value of min/max IEEE
Binary32, and we need 1 bit to represent the sign.  136 is 129 rounded to the
next 8 bits.

The plan is to have builtins that do the overflow check and convert 136-bit
numbers to the required width.  We need these builtins for both integers and
floating point numbers to ensure that 136-bit numbers are folded into sane
constants in SIL and don’t escape to LLVM IR.


Swift SVN r9253
2013-10-12 04:52:11 +00:00
Joe Groff
1bdbc97056 Drop the 'x as! T' cast syntax.
Now that we have a solid Optional-based story for dynamic casts, it's no longer needed, and can be expressed as '(x as T)!'. Future refinement of the 'as' syntax will deal with the unfortunate extra parens.

Swift SVN r9181
2013-10-10 23:47:59 +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
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Doug Gregor
d33d78acac Compute interface types for constructors.
Swift SVN r8992
2013-10-07 21:51:11 +00:00
Argyrios Kyrtzidis
b7e66f9111 [ASTDumper] Print the overridden decl.
Swift SVN r8961
2013-10-07 16:42:24 +00:00
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +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
Doug Gregor
36df570c15 Record the generic type of a generic function as its "interface" type.
We're still not using the interface type for anything, but record it
and serialize/deserialize it.


Swift SVN r8897
2013-10-04 00:14:04 +00:00
Joe Groff
fb7fb33be6 Sema: Synthesize raw type methods for enums.
If an enum has a valid raw type, synthesize a RawType associated type along with fromRaw and toRaw methods.

An implicit conformance to RawRepresentable is not yet set up. This synthesis may need to be done earlier in order for the names to be available during type-checking of definitions in the enum too.

Swift SVN r8890
2013-10-03 21:55:53 +00:00
Argyrios Kyrtzidis
781dcf7b11 [AST] Store the TypeReprs of generic arguments used to specialize a decl reference in DeclRefExpr, to impove source fidelity.
Fixes rdar://15034958

Swift SVN r8880
2013-10-03 17:55:55 +00:00
Argyrios Kyrtzidis
cb4e51c72b [ASTDumper] For UnresolvedSpecializeExpr, print out its TypeReprs.
Swift SVN r8878
2013-10-03 17:55:53 +00:00
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +00:00
Joe Groff
3b0180b1b0 Allow '_' in assignments again.
Parse '_' as a DiscardAssignmentExpr. Type-check it as an lvalue, and check that it only appears in the LHS of AssignExprs. During matching pattern resolution, convert it into an AnyPattern. In SILGen, when we see '_' in the LHS of an assignment, ignore the corresponding RHS rvalue.

Swift SVN r8848
2013-10-02 18:43:20 +00:00
Doug Gregor
5148c12c39 Dump the declared result type of a function declaration.
Swift SVN r8845
2013-10-02 17:57:30 +00:00
Argyrios Kyrtzidis
1165ab2b6e [ASTDumper] Only print both argument and body params if the function has selector-style syntax.
Swift SVN r8841
2013-10-02 16:30:10 +00:00
John McCall
6df6897756 Add an InjectIntoOptional implicit conversion expression
instead of generating ugly artificial calls to
_injectValueIntoOptional in the AST.

Swift SVN r8837
2013-10-02 05:48:30 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
Joe Groff
f1993cf231 Parse and type-check 'x as? T' conditional cast syntax.
Though we plan to revamp the casting syntax, our general plan is for this form of cast, which does a conditional cast and returns an Optional<T> result, to be the one that survives. Parse the status-quo syntax 'x as? T' and type-check it. While we're here, refresh some fixits for redundant casts that referred to the now defunct 'as T' coercion syntax to completely remove whatever cast was in the source code.

Swift SVN r8805
2013-10-01 17:00:54 +00:00
Joe Groff
911929f1dd Parse and type check initializer closures after 'new T[n]' exprs.
Require that either T be default constructible or that the user provide a closure that maps indices to initial values. We don't actually call the closure yet to initialize the array; that's blocked on function abstraction difference <rdar://problem/13251236>.

Swift SVN r8801
2013-10-01 05:12:54 +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
Argyrios Kyrtzidis
e461b3f267 [ASTDumper] Print the 'implicit'ness of a pattern.
Swift SVN r8794
2013-09-30 22:07:47 +00:00
Argyrios Kyrtzidis
2dfa03717c [ASTDumper] Print argument and body patterns of abstract function decls.
Swift SVN r8793
2013-09-30 22:07:45 +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
Doug Gregor
7de90d7822 Make Decl::dump() not print before it dumps.
Swift SVN r8726
2013-09-27 15:09:23 +00:00
Doug Gregor
0d33ff3f40 Teach SILGen to directly emit optional injection operations for dynamic lookup.
... rather than synthesizing expressions in the AST.


Swift SVN r8723
2013-09-27 14:12:33 +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
Argyrios Kyrtzidis
614a427a22 [ASTDumper] Print out whether an expression node is implicit.
Swift SVN r8602
2013-09-24 21:01:08 +00:00
Doug Gregor
f67aa78d69 Dynamic lookup for subscripts: semantic analysis and ASTs.
Swift SVN r8591
2013-09-24 05:51:30 +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
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Dmitri Hrybenko
f2cc4cb303 Rename CapturingExpr -> AbstractClosureExpr
Swift SVN r8299
2013-09-16 21:58:44 +00:00
Chris Lattner
ee1a9141a3 move the capture list up to AbstractFunctionDecl, and compute it
for all AbstractFunctionDecl's.  Refactor ASTDump of AbstractFunctionDecl's
to all go through the same funnel point and print it in the right place.


Swift SVN r8242
2013-09-14 04:25:43 +00:00
Chris Lattner
0e9b9c5b65 refactor ast dumping a bit to make room for AbstractFunctionDecl. Right now,
just have it print a body.



Swift SVN r8241
2013-09-14 04:17:42 +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
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +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
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +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
Doug Gregor
cdf160ecbd Introduce and optimize for uniquely-referenced opaque values.
If an OpaqueValueExpr is only used in one place, mark it as such. SIL
generation will then elide the retain/release pair associated with
each reference to the opaque value, instead consuming the value at the
point of use.


Swift SVN r8072
2013-09-10 18:03:55 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Doug Gregor
8c60d88f5a Provide DynamicMemberRefExpr with .Some(fn)/.None helper expressions.
These helper expressions will eventually be used by SILGen to help
package up the optional values. I expect that we'll eventually have
library builtins for this, so consider this a stop-gap until those
appear.

As part of this, make OpaqueValueExpr a bit more usable: it can now
persist in the AST as a placeholder, but its uses must be within AST
subtrees of some specific introduction point (similarly to how Clang's
OpaqueValueExpr works).


Swift SVN r8051
2013-09-09 19:58:51 +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
Chris Lattner
c75a339a26 for completeness, have -ast-dump print the captures list on FuncDecls as well as FuncExprs.
Swift SVN r7998
2013-09-06 20:46:32 +00:00
Doug Gregor
0dcca3aeda Eliminate CoerceExpr entirely.
Swift SVN r7876
2013-09-03 22:58:22 +00:00