Commit Graph

275 Commits

Author SHA1 Message Date
Jordan Rose
339c18c79f Don't replace a Swift module with a Clang one in the list of loaded modules.
We want to make sure that a global lookup always finds the Swift module
first. Moreover, we should never be loading two modules with the same name
into the same TU /unless/ they are (a) identical or (b) a Swift / C pair.

Swift SVN r3723
2013-01-10 00:53:57 +00:00
Doug Gregor
bfcd8274fe Every Swift file is a module; let name lookup find the name of the current module.
Swift SVN r3531
2012-12-18 21:41:58 +00:00
Doug Gregor
319a100189 Allow diagnostics to accept declarations in lieu of source locations.
Swift's diagnostic system is built on the quaint notion that every
declaration known to the front end has a valid source location to
which diagnostics mentioning that declaration (say, in a "here is a
candidate" note) can point. However, with a real module system, the
source corresponding to a declaration in a module does not need to be
present, so we can't rely on source locations.

Instead of source locations, allow diagnostics to be anchored at a
declaration. If that declaration has source-location information, it
is used. Otherwise, we just drop source-location information for
now. In the future, we'll find a better way to render this information
so it feels natural for the programmer.


Swift SVN r3413
2012-12-07 22:51:11 +00:00
Doug Gregor
608b2d8a5b Allow a Swift and a Clang module to have the same name, and load both.
This change allows client code to just use, e.g.,

  import Foundation

to get both the Clang Foundation module and the Swift Foundation
module that provides various adaptation (typically via
extensions). At some point later, we can consider whether the modules
will end up in different namespaces somehow, or whether this is best
tackled by some kind of module re-export directive, but for now it's
convenient while we await the design of a real module system for
Swift.



Swift SVN r3405
2012-12-07 18:23:35 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Doug Gregor
10664981aa Add command line options to turn on the two LangOptions options for
the constraint-based type checker:

  -constraint-checker turns on constraint-based type checking for the
   current swift module (but not imported modules; we're not ready for that)
  
  -debug-constraints turns on detailed debugging information for the
   constraint-based type checker

Use these flags to de-REPL-ify the tests for the constraint-based type
checker. The REPL is still quite useful for experimenting with the
type checker, but shouldn't be our normal means of testing it.



Swift SVN r2840
2012-09-12 21:19:49 +00:00
Eli Friedman
8f85913c2b Start of support for semantic analysis of generic base classes.
Swift SVN r2729
2012-08-23 23:04:43 +00:00
Eli Friedman
da954c0cbd Minor cleanup for type validation: a type only needs to be validated once,
and type validation should never fail in a call to validateTypeSimple.

The one thing I really don't like about this whole approach is that we end
up with validateTypeSimple calls scattered all over the place...
the ultimate solution here is probably something along the lines of
introducing getUnvalidated() getters for types for use from the parser,
and make the standard getters for types assert that the type is valid
and perform any necessary computations themselves.



Swift SVN r2728
2012-08-23 22:42:36 +00:00
Eli Friedman
eb1689710f Delete isa, cast, and dyn_cast on Type. Hopefully, this will lead to fewer stupid mistakes.
Swift SVN r2691
2012-08-20 22:15:10 +00:00
Eli Friedman
7f2973347c Fix type lookup into base classes to work roughly correctly.
Swift SVN r2603
2012-08-10 00:20:53 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Eli Friedman
960b0bfd35 Move most type lookup from name-binding into TypeChecker::validateType. Use this to make type resolution more powerful, so we can resolve members of types like S<Int>
and Int[].

Type resolution for types named in ExtensionDecls remains a part of name-binding; it has to use more restrictive rules because we can't perform general member lookup until
we've resolved all the types named in ExtensionDecls.



Swift SVN r2313
2012-07-06 01:51:09 +00:00
Eli Friedman
6258942b30 Explicitly specify whether we're performing type lookup to the name lookup code, rather than deducing it from the translation phase.
Swift SVN r2312
2012-07-06 01:06:46 +00:00
Eli Friedman
a54c5493da Per discussion with Doug, add UnboundGenericType and BoundGenericType to represent generic types.
Swift SVN r2304
2012-07-04 01:17:16 +00:00
Eli Friedman
ab2998431c Simplify our handling of tuple elements in the AST and Sema.
Swift SVN r2224
2012-06-21 21:30:57 +00:00
Doug Gregor
f4bdd9ddf3 Introduce support for using static protocol functions within generics.
Swift SVN r2216
2012-06-20 17:59:03 +00:00
Eli Friedman
1cd0a47628 Allow referring to member types using dotted syntax, at least in most contexts. This should cover the cases we care about for generics, although I'm not
really satisfied with the restrictions on extensions.



Swift SVN r2210
2012-06-20 00:55:09 +00:00
Doug Gregor
f847fe4a22 Introduce basic support for type-checking the definitions of generic
functions. This involves a few steps:

  - When assigning archetypes to type parameters, also walk all of the
  protocols to which the type parameter conforms and assign archetypes
  to each of the associated types.
  - When performing name lookup into an archetype, look into all of
  the protocols to which it conforms. If we find something, it can be
  referenced via the new ArchetypeMemberRefExpr.
  - When type-checking ArchetypeMemberRefExpr, substitute the values
  of the various associated types into the type of the member, so the
  resulting expression involves the archetypes for the enclosing
  generic method.

The rest of the type checking essentially follows from the fact that
archetypes are unique types which (therefore) have no behavior beyond
what is provided via the protocols they conform to. However, there is
still much work to do to ensure that we get the archetypes set up
correctly.



Swift SVN r2201
2012-06-19 21:16:14 +00:00
Eli Friedman
8a12c79319 Fix a silly assertion failure with a file with no valid decls. <rdar://problem/11600182>.
Swift SVN r2179
2012-06-08 23:09:29 +00:00
Eli Friedman
d829b3c775 Unify the complete unqualified lookup logic in the UnqualifiedLookup class.
Swift SVN r2109
2012-06-01 23:26:58 +00:00
Eli Friedman
0e7ef8cebb Start refactoring code towards a single complete implementation of unqualified lookup.
Swift SVN r2108
2012-06-01 01:37:44 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
29a13e9ae0 Move the NameLookup class into the AST library.
Swift SVN r2101
2012-05-31 22:35:50 +00:00
Eli Friedman
377972b1ba Start shuffling around code for name binding on values; with the proposed shadowing rules, we need to delay name binding on values until after some parts of type-checking.
Swift SVN r1946
2012-05-23 00:42:53 +00:00
Doug Gregor
9552aa5e10 Implement basic support for refering to a nested type within
unqualified lookup, based on context. For example:

struct String {
  struct CharRange { /* ... */ }
  
  func getElements() -> CharRange {
    return CharRange(value)
  }
}




Swift SVN r1939
2012-05-22 21:08:22 +00:00
Doug Gregor
b1f1e1430d Introduce NominalType as a base class of
OneOfType/StructType/ClassType/ProtocolType, an eliminate the
ridiculous chained ifs that used to check for most (or all) of these.


Swift SVN r1923
2012-05-22 00:13:59 +00:00
Doug Gregor
70bfc235b8 Implement protocol inheritance, e.g.,
protocol Document { var title : String }
  protocol Versioning { func bumpVersion() }
  protocol VersionedDocument : Document, Versioning { }

This commit covers the basic functionality of protocol inheritance, including:
  - Parsing & AST representation
  - Conforming to a protocol also requires conforming to its inherited
  protocols
  - Member lookup into a protocol also looks into its inherited
  protocols (results are aggregated; there is no name hiding)
  - Teach ErasureExpr to maintain lvalueness, so we don't end up
  performing a silly load/erase/materialize dance when accessing
  members from an inherited protocol.




Swift SVN r1804
2012-05-11 00:00:50 +00:00
Eli Friedman
05fe3c907f Propagate a DeclContext through NameBinding for IdentifierTypes.
Swift SVN r1803
2012-05-10 23:34:01 +00:00
Eli Friedman
77fa49ec2b Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
5f2344afe0 Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
guts of ProtocolType over to ProtocolDecl.


Swift SVN r1778
2012-05-08 23:28:55 +00:00
Eli Friedman
22ef9b45c7 Avoid using TypeBase* directly in a case where it isn't necessary.
Swift SVN r1775
2012-05-08 21:12:28 +00:00
Eli Friedman
4ca443d0f5 Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
Swift SVN r1774
2012-05-08 21:09:42 +00:00
Eli Friedman
a143422c98 Teach name binding to look into default values for tuple types.
Swift SVN r1747
2012-05-04 23:09:55 +00:00
Eli Friedman
e6177f35a9 Get rid of the outdated notion of type lookup in Module. <rdar://problem/11026489>.
Swift SVN r1734
2012-05-04 00:41:54 +00:00
Eli Friedman
2f3ff69d41 Some tweaks to module import to get the demo flow working.
Swift SVN r1625
2012-04-25 07:29:31 +00:00
Eli Friedman
c055f6293f Initial implementation of global redeclaration checking. <rdar://problem/11294839>.
Swift SVN r1613
2012-04-24 23:10:03 +00:00
Doug Gregor
a04776044e Teach the import mechanism that it's rude to parse the same library
multiple times, as well as teaching the name lookup mechanism that
it's similarly rude to report ambiguous results because it searched
the same import twice. Fixes <rdar://problem/11287213>.

Yes, this is a bit of an ugly hack.


Swift SVN r1610
2012-04-24 22:36:17 +00:00
Eli Friedman
36472404b2 Parse swift.swift upfront in the REPL. This has two benefits: one, we error immediately if swift.swift can't be found, or something is wrong with it. Two, it lets us JIT swift.swift upfront, which makes the REPL prompt feel more responsive. <rdar://problem/11305258>.
Swift SVN r1575
2012-04-24 00:55:19 +00:00
Eli Friedman
a2c6150c13 Error recovery for the REPL. Seems to be working reasonably well. <rdar://problem/11269380>.
Swift SVN r1523
2012-04-20 01:14:39 +00:00
Eli Friedman
be602fcd05 Get rid of the implicit BraceStmt for the TranslationUnit; instead, have the TranslationUnit directly store a list of decls.
Swift SVN r1521
2012-04-20 00:17:13 +00:00
Eli Friedman
acc17d69aa Initial implementation of the "print" part of the REPL.
Swift SVN r1484
2012-04-19 01:13:37 +00:00
Eli Friedman
37de44a35d Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
Next step: implement an actual REPL.



Swift SVN r1441
2012-04-16 23:52:01 +00:00
Eli Friedman
9bf8dcf0f1 Delete some dead code.
Swift SVN r1412
2012-04-13 01:05:12 +00:00
Eli Friedman
1569d73cb2 Fix a crash involving extensions.
Swift SVN r1411
2012-04-13 00:48:53 +00:00
Doug Gregor
ba56d2c0b1 Implement support for lookup of members of the current
oneof/struct/protocol within a static method. The lookup is performed
on the metatype (as one would get when using qualified syntax
Type.member). Add tests to verify that this provides proper
overloading behavior.

As a drive-by, actually set the type of the implicit 'this' variable
during name binding for a non-static method.



Swift SVN r1394
2012-04-11 18:22:53 +00:00
Ted Kremenek
352453a53b Revert "Fix a bunch of "has virtual functions but non-virtual destructor" warnings"
Swift SVN r1376
2012-04-11 00:02:16 +00:00
Ted Kremenek
8a61ea1fd0 Fix a bunch of "has virtual functions but non-virtual destructor" warnings
Swift SVN r1373
2012-04-10 23:53:46 +00:00
Eli Friedman
bb597c7a37 Minor cleanup.
Swift SVN r1354
2012-04-10 01:47:45 +00:00
Doug Gregor
c24d6ec8c4 Factor OverloadSetRefExpr into an abstract base class covering the
notion of a reference to a set of declarations. Introduce one derived
class, OverloadedDeclRefExpr, which covers the only case we currently
handle for overload resolution [*]: a direct (unqualified) reference
to an overloaded set of entities. Future subclasses should handle,
e.g., overloaded member references such as a.b or a.b.c.

[*] Ugly hacks for static methods notwithstanding


Swift SVN r1345
2012-04-09 17:16:11 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00