Commit Graph

1293 Commits

Author SHA1 Message Date
Doug Gregor
0554c944a2 Fold GenericSubscriptExpr into SubscriptExpr.
Swift SVN r7845
2013-09-03 16:25:07 +00:00
Doug Gregor
786f9d299b Fold GenericMemberRefExpr into MemberRefExpr.
MemberRefExpr now uses ConcreteDeclRef to refer to its member, which
includes the substitutions and obviates the need for
GenericMemberRefExpr.


Swift SVN r7842
2013-09-03 15:49:19 +00:00
Doug Gregor
fc5d0b9ad3 Use ValueDecl::dumpRef() for dumping references.
Swift SVN r7841
2013-09-03 15:23:02 +00:00
Doug Gregor
967072f4b3 Allow dynamic lookup to find a generic member.
The new ConcreteDeclRef class provides a possibly-speciaized reference
to a declaration, which allows DynamicMemberRefExpr to refer to both
generic and non-generic members. without having to split the AST node.


Swift SVN r7839
2013-09-03 14:55:31 +00:00
Doug Gregor
b06e65c3b3 Add the DynamicLookup protocol for lookup across all classes and protocols.
When performing member lookup into an existential that involves the
DynamicLookup protocol, look into all classes and protocols for that
member. References to anything found via this lookup mechanism are
returned as instances of Optional.

This introduces the basic lookup mechanics into the type
checker. There are still numerous issues to work through:
  - Subscripting isn't supported yet
  - There's no SILGen or IRGen support
  - The ASTs probably aren't good enough for the above anyway
  - References to generics will be broken
  - Ambiguity resolution or non-resolution

Thanks to Jordan for the patch wiring up DynamicLookup.


Swift SVN r7689
2013-08-28 21:38:50 +00:00
Sean Callanan
6fd2cd3686 Added the option to TranslationUnit::dump() to
have the output go to a provided ostream.  This
allows it to be used for logging in LLDB.


Swift SVN r7681
2013-08-28 19:57:38 +00:00
Dmitri Hrybenko
d9035426ed Rename RebindThisInConstructorExpr -> RebindSelfInConstructorExpr
Swift SVN r7658
2013-08-28 03:02:30 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Doug Gregor
7c84fd5926 Start detangling archetypes from the interface of generic functions.
This breaks the type-canonicalization link between a generic parameter
type and the archetype to which it maps. Generic type parameter types
are now separate entities (that can eventually be canonicalized) from
archetypes (rather than just being sugar).

Most of the front end still traffics in archetypes. As a step away
from this, allow us to type-check the generic parameter list's types
prior to wiring the generic type parameter declarations to archetypes,
using the new "dependent" member type to describe assocaited
types. The archetype builder understands dependent member types and
uses them to map down to associated types when building archetypes.

Once we have assigned archetypes, we revert the dependent identifier
types within the generic parameter list to an un-type-checked state
and do the type checking again in the presence of archetypes, so that
nothing beyond the generic-parameter-list checking code has to deal
with dependent types. We'll creep support out to other dependent types
elsewhere over time.



Swift SVN r7462
2013-08-22 18:07:40 +00:00
John McCall
7df930b86e Remove some more uses of getTypeOfReference.
Swift SVN r7417
2013-08-21 19:27:23 +00:00
Dmitri Hrybenko
1fd528c15b Add ErrorTypeRepr, which is constructed during parser recovery for a type with
a syntax error.  Usually the type parsing can just return nullptr for the
TypeRepr, but when we want to construct an AST node that should have included
that type, we should provide a non-null TypeRepr.


Swift SVN r7375
2013-08-20 22:24:15 +00:00
Dmitri Hrybenko
5b952b080a Rename OOD and OOED variables that used to stand for OneOfDecl and
OneOfElementDecl


Swift SVN r7283
2013-08-16 18:11:28 +00:00
Dmitri Hrybenko
ce54da3123 Use NullablePtr in ForStmt
ForStmt::Cond is already a NullablePtr<>.  This patch changes
ForStmt::Initializer and ForStmt::Increment to be NullablePtr.  Otherwise it
looks like Cond can be null, while Initializer and Increment can not.


Swift SVN r7265
2013-08-15 17:51:32 +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
Chris Lattner
117f47f527 remove the hasFixedLifetime bit from ValueDecl, now that AST-level
capture analysis is gone.  This functionality is subsumed by SIL passes,
which turn boxes into stack allocations.

One minor detail of this is that dealloc_ref isn't implemented yet in IRGen
(rdar://14648382) and SILGen produces it for destructors (e.g. see 
test/SILGen/lifetime.swift).  To unblock progress, I just removed the 
llvm_unreachable in IRGen.


Swift SVN r6890
2013-08-05 14:59:08 +00:00
Chris Lattner
a70a4e7994 remove the NeverUsedAsLValue bit from ValueDecl - the only client was the ASTDumper.
Swift SVN r6884
2013-08-05 14:09:17 +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
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Argyrios Kyrtzidis
21785c8a36 Call Type::print(), instead of TypeBase::print(); the former includes the null check.
Swift SVN r6751
2013-07-30 21:25:36 +00:00
Dmitri Hrybenko
c0096e9584 ASTDumper: don't crash when printing an integer literal that has ErrorType
Swift SVN r6569
2013-07-24 23:11:23 +00:00
Doug Gregor
a0b1ec651a When printing an integer literal, use the text form when the type contains a type variable.
Swift SVN r6445
2013-07-22 14:47:40 +00:00
Argyrios Kyrtzidis
68ed84fe68 Allow TypeLocs as parameters to diagnostics.
Eventually TypeLocs coming from the Parser will contain only a TypeRepr and the TypeChecker will resolve and add the type.
Passing a TypeLoc to a diagnostic means "print as user written" (even before typechecking)
and if there is no TypeRepr (e.g. due to a TypeLoc coming from a module without location info) print the type.

Swift SVN r6280
2013-07-16 01:39:35 +00:00
Joe Groff
844465d9b9 Resolve and type-check OneOfElementPatterns.
If we see '.Foo' or '.Foo(...)' in a case, resolve it as a OneOfElementPattern with element to be determined at type-checking time. If we see 'A.B' or 'A.B(...)', try to resolve 'A.B' as a qualified reference to a OneOfElementDecl, and resolve the expression as a OneOfElementPattern referencing that decl if we find one. During type-checking, resolve the element decl for unresolved OneOfElementPatterns, then match the subpattern to the type of the element's associated data (or void if it has none).

A few cases don't yet work right that ought to:

- Qualified references to generic oneof cases with generic arguments elided, e.g. 'case Optional.None:'
- Qualified references to generic oneof cases through a module, e.g. 'case swift.Optional<Int>.None:'

Swift SVN r6278
2013-07-16 01:25:34 +00:00
Argyrios Kyrtzidis
37dc84e13c Remove VarargBaseType from TuplePatternElt and introduce a bit in TuplePattern to indicate if there is a vararg.
The semantics of varargs (only for the last element) make it more appropriate as a property of the TuplePattern.
Also free the Parser from needing to construct synthetic types (ArraySlice for type of vararg element) to
accommodate the TypeChecker and move the logic to the TypeChecker. This will be more beneficial when the parser stops
creating types in general.

Swift SVN r6271
2013-07-15 20:21:30 +00:00
Doug Gregor
cf9b8a302e Remove the notion of 'unresolved' types entirely.
Unresolved types are a holdover from the old type checker that not
longer have any purpose in the type system.


Swift SVN r6242
2013-07-13 05:27:22 +00:00
Joe Groff
3b21e6a201 Add a OneOfElementPattern AST node type.
Add a node for references to oneof cases in patterns. No user-facing functionality change yet.

Swift SVN r6239
2013-07-13 01:21:31 +00:00
Doug Gregor
5639fa888c Remove the initializer for NamedTypeRepr; types don't have default values.
Swift SVN r6163
2013-07-11 18:10:30 +00:00
Argyrios Kyrtzidis
3df3878490 [AST/TypeRepr] Address feedback by Doug.
-Add some FIXMEs
-Rename CompositeTypeRepr -> ProtocolCompositionTypeRepr
-Fix dumping of AttributedTypeRepr

Swift SVN r6150
2013-07-11 17:00:53 +00:00
Argyrios Kyrtzidis
a70eff6609 Introduce TypeRepr and related subclasses, that is a representation of a type as written in source.
This the first part for improving source location fidelity for types,
changes to follow:

-The Parser will not create any types, it will just create TypeReprs.
-The type checker will create the types by going through TypeReprs.
-IdentifierType will be removed.

Swift SVN r6112
2013-07-10 14:58:52 +00:00
Argyrios Kyrtzidis
7d3f33b505 [ASTDumper] Dump patterns as a tree, and more details from them (e.g. any Expr that may contain).
Swift SVN r6096
2013-07-09 22:18:35 +00:00
Jordan Rose
b31e79e571 Sink InfixOperatorDecl's InfixData into Decl's bitfields.
InfixData is still useful, since the type-checker uses it to treat other
operator-like constructs (e.g. 'is') the same way.

Swift SVN r6077
2013-07-08 23:40:58 +00:00
Doug Gregor
09e64a0243 Resolve unbound generic type references within their definitions.
When the name of a generic type is referenced, without any generic
arguments, within the definition of a generic type (or extensions of
that generic type), use the generic arguments provided by that
context. Thus, within the definition of X<T> below, one can simply use
'X' as a shorthand for 'X<T>':

  class X<T> {
    func swap(other : X) { /* ... */ } // same as "func swap(other : X<T>)"
  }

This resolution provides essentially the same behavior as the
injected class name does in C++. Note that this rule overrides any
inference rules, such that (for example) the following is ill-formed
rather than inferring the generic arguments of 'X':

  class X<T> {
    func foo() {
      var xi : X<Int> = X()
    }
  }

Note that name binding has changed slightly: when unqualified lookup
finds a type declaration within a nominal type, it is now treated as
a DeclRefExpr (or overloaded variant thereof) rather than as a member
access with an implicit 'this'.

Fixes <rdar://problem/14078437>.



Swift SVN r6049
2013-07-08 16:17:12 +00:00
Argyrios Kyrtzidis
f478157ab4 Revert "Print source ranges of the AST nodes when dumping the AST."
See if it fixes the buildbot.
This reverts commit 5957.

Swift SVN r5960
2013-07-02 16:45:07 +00:00
Argyrios Kyrtzidis
0a3fc1b195 Print source ranges of the AST nodes when dumping the AST.
Swift SVN r5959
2013-07-02 00:42:01 +00:00
Chris Lattner
2fe98e14e7 implement basic __FILE__, __LINE__, and __COLUMN__ magic identifiers.
Swift SVN r5912
2013-06-30 21:19:32 +00:00
Joe Groff
bec638856d Sema: Resolve tuple patterns.
Preprocess case label patterns with a ResolvePattern pass that pushes pattern-ness down the AST through tuples of patterns.

Swift SVN r5900
2013-06-30 03:56:25 +00:00
Joe Groff
b5d6103bfc AST: Add an UnresolvedPatternExpr to parse patterns in expr position.
Because of '~=' lookahead and precedence parsing, we need to be able to parse pattern productions in expression position and validate them after name binding. Add an unresolved Expr node that can hold a subpattern for this purpose.

Swift SVN r5825
2013-06-27 00:01:14 +00:00
Joe Groff
53221db84c AST: Add 'VarPattern' node.
We decided to go with 'var' as a distributive pattern introducer which applies to bare identifiers within the subpattern. For example, 'var (a, b)' and '(var a, var b)' would be equivalent patterns. To model this, give 'var' its own AST node with a subpattern and remove the introducer loc from NamedPattern.

Swift SVN r5824
2013-06-26 23:01:47 +00:00
Joe Groff
e460a01af6 Remove the 'UnresolvedCallPattern' I stubbed out.
I talked to John about parsing patterns today, and because of the magnitude of name-lookup-dependent ambiguities between patterns and expressions, we agreed that at least for a first-pass implementation it makes sense to parse patterns as extensions of the expr grammar and charge name binding with distinguishing patterns from expressions. This gets us out of needing the concept of an "unresolved pattern", at least in the short term.

Swift SVN r5808
2013-06-26 04:23:47 +00:00
Joe Groff
8deec52b17 Rework AST representation of CaseStmts.
A single case block can have one or more 'case ...:' labels. 'case' labels contain patterns instead of exprs. 'default:' is a funny spelling for 'case _:'. Change the CaseStmt representation and rip out all the parsing, type-checking, and SILGen built off the old representation.

Swift SVN r5795
2013-06-25 00:31:42 +00:00
Joe Groff
7ba95cfd26 Add AST nodes for refutable patterns.
Introduce Pattern subclasses for the 'is T', 'T(<pattern>)', and '<expr>' pattern syntaxes we'll be introducing for pattern-matching "switch" statements. Also add an 'UnresolvedCalLPattern' to act as an intermediate for name lookup to resolve to a nominal type, oneof element, or function call expression pattern. Since we'll need to be able to rewrite patterns like we do expressions, add setters to AST nodes that contain references to subpatterns. Implement some basic walking logic in places we search patterns for var decls, but punt on any more complex type-checking or SILGen derived from these nodes until we actually use them.

Swift SVN r5780
2013-06-24 17:17:34 +00:00
Argyrios Kyrtzidis
c7b33908ae Move the dumping visitors (PrintDecl/PrintStmt/PrintExpr) into one separate source file, so that they can easily share code, colors, and internal details.
Swift SVN r5770
2013-06-22 17:39:01 +00:00