Commit Graph

1316 Commits

Author SHA1 Message Date
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Chris Lattner
39224db6a9 remove the ZeroValueExpr AST node.
Swift SVN r11048
2013-12-09 23:16:14 +00:00
Joe Groff
0372bedff7 Give ProtocolConformance a 'printName' member.
This prints the identifying info for a protocol conformance without the actual witness maps, recursively naming specialized or inherited conformances.

Swift SVN r10899
2013-12-06 01:32:36 +00:00
Nadav Rotem
ccf3a127f2 Add a simple generic specialization pass.
Swift SVN r10885
2013-12-05 22:20:05 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Doug Gregor
627f0ae447 Allow "x as T" to perform implicit conversions from x to T.
Fixes <rdar://problem/15283100>.


Swift SVN r10783
2013-12-04 17:31:44 +00:00
Doug Gregor
19759529db Allow delayed identifier expressions (.foo) with static variables and methods.
This allows expressions such as ".foo" and ".foo(1)" to refer to
static variables and static methods, respectively, as well as enum
cases. 

To get here, rework the parsing of delayed identifier expressions a
bit, so that the argument itself is part of the delayed argument
expression rather than a separate call expression. This simplifies
both the handling of patterns of this form and the type checker, which
can now user simpler constraints.

If we really want to support (.foo)(1), we can make that work, but it
seems unnecessary and perhaps confusing.


Swift SVN r10626
2013-11-21 06:24:06 +00:00
Joe Groff
3e48f592dc Sema: Resolve static property refs in the type-checker.
Handle the static var case in various places in the type-checker where it was assumed not to happen. For simplicity, build static var references as DeclRefs for now, with an assert to ensure we fix this before turning on potentially dynamic cases.

Swift SVN r10372
2013-11-12 17:29:16 +00:00
Joe Groff
d873764add Sema: Allow an implicit conversion from T? to U? if T can be converted to U.
Similar to the T -> U? conversion, allow T? to be converted to U? through a bind-convert-inject chain. Naively adding this conversion creates ambiguities in the type checker, opening up multiple paths to the same solution in certain cases, so add a a special case to the solver that avoids introducing the conversion if a solution is already available by other means. (Doug figured out that part; thanks Doug!)

This still introduces a regression in test/Constraints/optional.swift, rendering a call ambiguous when overloaded on argument types. <rdar://problem/15367036>

Swift SVN r9857
2013-10-31 22:51:36 +00:00
Doug Gregor
f342493144 Give every declaration an interface type.
For declarations that aren't generic and aren't in a generic context,
the interface type is the same as the normal type.


Swift SVN r9847
2013-10-31 17:38:42 +00:00
Doug Gregor
f473246f56 Dump associated type declarations
Swift SVN r9780
2013-10-30 04:13:20 +00:00
Doug Gregor
112c6123eb Terminate SpecializeExpr with extreme prejudice.
There are numerous other cleanups that could be performed now that
this is gone; I'll follow up with some of them.


Swift SVN r9717
2013-10-28 18:50:29 +00:00
Doug Gregor
731fe651e7 Teach OtherConstructorDeclRefExpr to track substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9714
2013-10-28 18:35:49 +00:00
Doug Gregor
3b37cbab4f Dump interface types for any value declaration.
Swift SVN r9687
2013-10-26 03:02:07 +00:00
Doug Gregor
8ea71f06a7 Teach ExistentialMemberRefExpr to handle all levels of substitutions.
Another SpecializeExpr usage bites the dust.


Swift SVN r9665
2013-10-25 00:02:36 +00:00
Doug Gregor
10164fa56c Teach ArchetypeMemberRefExpr to handle all levels of substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9655
2013-10-24 21:44:45 +00:00
Jordan Rose
0702acab3d Make SourceFile a DeclContext, but don't actually do anything with it yet.
Swift SVN r9646
2013-10-24 18:59:21 +00:00
Jordan Rose
ec23db6962 Push the TU's lookup cache down to SourceFile.
Also move print() and dump() from TranslationUnit to SourceFile.

Swift SVN r9645
2013-10-24 18:59:18 +00:00
Doug Gregor
d8b647398e Dump DeclRefExpr's ConcreteDeclRef appropriately.
Swift SVN r9604
2013-10-22 23:05:06 +00:00
Dmitri Hrybenko
aa337de4ef AST Dumper: ensure that all output goes to the given raw_ostream
Swift SVN r9602
2013-10-22 22:23:20 +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
Argyrios Kyrtzidis
791d9b74f5 [ASTDumper] Centralize the ValueDecl-specific dumping to one function.
Swift SVN r9579
2013-10-22 05:44:10 +00:00
Dmitri Hrybenko
acdd5b120a Make type checker debug output redirectable
Introduce a replaceable TypeCheckerDebugConsumer for this.


Swift SVN r9555
2013-10-21 20:26:32 +00:00
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