Commit Graph

1019 Commits

Author SHA1 Message Date
Jordan Rose
79b45268e2 Allow ASTContext::getStdlibModule to load the stdlib if it isn't present.
This is better than requiring people to go through Ctx.getModule() using
Ctx.StdlibModuleName. There aren't that many cases of this, but they
shouldn't be using a completely different API.

The default behavior remains the same: if the standard library has not been
loaded, null will be returned.

Refinement of r18796, which modified the behavior of SourceFiles to assume
that the standard library had already been loaded.

Swift SVN r18813
2014-06-11 23:34:41 +00:00
Jordan Rose
ea8e7f56d8 Module::forAllVisibleModules should use a proper pre-order traversal.
Previously, it had a *nearly* pre-order traversal, but included private
imports before the top-level module being searched. This was leading to
strange errors that relied on search order, like
<rdar://problem/17127940> Qualifying Swift types by their module name doesn't work

Swift SVN r18806
2014-06-11 19:02:04 +00:00
Jordan Rose
e022a97386 [Frontend] Check in advance that we can load the standard library.
This doesn't really affect anyone in real life, but it will catch cases
where someone's trying to compile for iOS without the iOS stdlib around.

Swift SVN r18796
2014-06-11 00:02:00 +00:00
Dmitri Hrybenko
187e444200 Code completion: don't report duplicate results for top-level declarations
rdar://16953526


Swift SVN r18323
2014-05-18 15:35:46 +00:00
Joe Groff
6b74826898 Improve diagnostic for @UIApplication mixed with top-level code.
Drop a note in the source file containing the top-level code to make it easier to navigate to (and avoid hardcoding the magic "main.swift" name).

Swift SVN r18093
2014-05-15 01:14:59 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Joe Groff
6e13190f47 Diagnose when @UIApplicationMain tries to coexist with a main.swift file.
Swift SVN r18072
2014-05-14 16:10:29 +00:00
Joe Groff
09d8d68099 Allow at most one main class per module.
Register valid @UIApplicationMain classes with the enclosing module, and diagnose when we see more than one.

Swift SVN r18061
2014-05-14 04:40:30 +00:00
Argyrios Kyrtzidis
918f373d97 [AST] For USR generation, ignore symbols coming from the builtin module.
Swift SVN r17858
2014-05-11 00:00:57 +00:00
Argyrios Kyrtzidis
9afa0333db [Frontend] Make sure we don't do any module imports during parse-only pass.
Fixes performance regression of rdar://16816861

Swift SVN r17600
2014-05-07 02:37:49 +00:00
Jordan Rose
d9fc1c4fb9 Treat AnyObject conformance for an archetype or existential specially.
These types may not have a conformance for AnyObject explicitly declared,
but being class-bound in some other way is good enough.

<rdar://problem/16818324>

Swift SVN r17581
2014-05-06 23:24:14 +00:00
Doug Gregor
6b3ef547ec Replace "Members" arrays with an intrusive linked list.
The use of ASTContext-allocated arrays to store the members of nominal
type declarations and the extensions thereof is an
abomination. Instead, introduce the notion of an "iterable"
declaration context, which keeps track of the declarations within that
context (stored as a singly-linked list) and allows iteration over
them. When a member is added, it will also make sure that the member
goes into the lookup table for its context immediately.

This eliminates a ton of wasted memory when we have to reallocate the
members arrays for types and extensions, and moves us toward a much
more sane model. The only functionality change here is that the Clang
importer no longer puts subscript declarations into the wrong class,
nor does it nested a C struct within another C struct.



Swift SVN r16572
2014-04-19 23:37:06 +00:00
Doug Gregor
36889a2b1a Introduce DeclIterator and DeclRange for iterating over decl members.
NFC. DeclRange is a range over DeclIterators, and is used rather than
ArrayRef<Decl*> to retrieve the members of a nominal type declaration
or extension thereof. The intent is to change the representation of
DeclRange next.


Swift SVN r16571
2014-04-19 18:53:20 +00:00
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
Joe Groff
96c09d7179 Renovate name lookup to prepare for compound name lookup.
Make the name lookup interfaces all take DeclNames instead of identifiers, and update the lookup caches of the various file units to index their members by both compound name and simple name. Serialized modules are keyed by identifiers, so as a transitional hack, do simple name lookup then filter the results by compound name.

Swift SVN r14768
2014-03-07 03:21:29 +00:00
Dmitri Hrybenko
cd48638f9a Fix a use-after-free caused by creating DerivedFileUnit on the fly
Sema was creating DerivedFileUnit on the fly, while something else is iterating
over FileUnits in the module.  The fix is to create DerivedFileUnit in advance.
This change immediately uncovered a lot of code that assumed that the module
consists of a single FileUnit at certain conditions.  This patch also fixes
that code (SourceKit patch is separate, not sending it).

The test change is because now operator == on NSObjects is correctly recognised
as coming from a system module.

rdar://16153700, rdar://16227621, possibly rdar://16049613


Swift SVN r14692
2014-03-05 22:24:25 +00:00
Jordan Rose
1fe8630bcd Accept (and prefer) "import type" as a scoped import for any non-protocol type.
Previously this was spelled "import typealias", and that spelling will
continue to be allowed (since someone may specifically be importing a
typealias and want that to match), but now that 'type' is a keyword,
"import type" is the right way to spell the generic "import any type"
scoped import.

Swift SVN r14488
2014-02-27 23:46:06 +00:00
Jordan Rose
7ac2c1de2f Add missing access path filters for DerivedFileUnit.
I can't see this ever actually being an issue, but if someone performs a
scoped import on another module, and that module synthesizes a derived
declaration, further lookups shouldn't find that declaration if the name
doesn't match the import scope.

Swift SVN r14487
2014-02-27 23:46:05 +00:00
Joe Groff
8e6b353542 Derive conformances of Equatable and Hashable for simple enums.
If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
2014-02-27 20:28:38 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Doug Gregor
926e3711d0 Only permit inheritance of protocol conformance when it is semantically valid.
A protocol conformance of a class A to a protocol P can be inherited
by a subclass B of A unless
  - A requirement of P refers to Self (not an associated type thereof)
  in its signature, 
    + *except* when Self is the result type of the method in P and the
    corresponding witness for A's conformance to B is a DynamicSelf
    method.

Remove the uses of DynamicSelf from the literal protocols, going back
to Self. The fact that the conformances of NSDictionary, NSArray,
NSString, etc. to the corresponding literal protocols use witnesses
that return DynamicSelf makes NSMutableDictionary, NSMutableArray,
NSMutableString, and other subclasses still conform to the
protocol. We also correctly reject attempts to (for example) create an
NSDecimalNumber from a numeric literal, because NSNumber doesn't
provide a suitable factory method by which any subclass can be literal
convertible.



Swift SVN r14204
2014-02-21 07:48:28 +00:00
Jordan Rose
0b2541b58f Rename the standard library to "Swift" (instead of "swift")
This is more in line with all other modules currently on our system.
If/when we get our final name for the language, we're at least now set
up to rename the library without /too/ much trouble. (This is mostly just
a lot of searching for "import swift", "swift.", "'swift'", and '"swift"'.
The compiler itself is pretty much just using STDLIB_NAME consistently now,
per r13758.)

<rdar://problem/15972383>

Swift SVN r14001
2014-02-17 19:30:47 +00:00
Jordan Rose
7995dde448 Module::getImportedModules can now get public, private, or all imports.
...whereas before the only options were "public" and "all".

No functionality change.

Swift SVN r13849
2014-02-12 23:57:43 +00:00
Joe Groff
05daca8e79 IRGen: Use interface types to implement the PolymorphicConvention.
Refactor the base PolymorphicConvention implementation to work using generic signatures and dependent types instead of GenericParamLists and archetypes, using an ArchetypeBuilder to produce representative archetypes as a convenience when we need to consider all of the requirements attached to a dependent type. In EmitPolymorphicParameters, map the dependent types into context to resolve the archetypes that should be bound in the body of the function.

Swift SVN r13685
2014-02-08 21:04:15 +00:00
Jordan Rose
cbcf17f9bd Stop leaking memory from Module and FileUnit.
Also, disallow creating Modules and FileUnits on the stack. They must always
live as long as the ASTContext.

<rdar://problem/15596964>

Swift SVN r13671
2014-02-08 02:12:57 +00:00
Jordan Rose
0f7a1e2cc6 Re-apply "[serialization] Preserve dependencies when merging modules."
This re-applies r13401, reverted in r13404. This wasn't actually causing
problems, but got pulled along with r13400 (reverted in r13405).

Swift SVN r13452
2014-02-04 22:46:50 +00:00
Michael Gottesman
a602f130e7 Revert "[serialization] Preserve dependencies when merging modules."
This reverts commit r13401. This broke the build.

Swift SVN r13404
2014-02-04 05:48:50 +00:00
Jordan Rose
fcdf8a4542 [serialization] Preserve dependencies when merging modules.
Swift SVN r13401
2014-02-04 01:32:47 +00:00
Argyrios Kyrtzidis
742cffb715 [AST] Add an out-of-line destructor for SourceFile.
Note that we are currently leaking memory via SourceFile, see rdar://15964312

Swift SVN r13312
2014-02-02 03:14:30 +00:00
Doug Gregor
b6210f7daf Start substituting type variables through protocol conformances.
This eliminates a class of strange type checking failures involving
generics. The actual example is from <rdar://problem/15772601>, but
this also addresses <rdar://problem/15268030> and the root problem,
<rdar://problem/15168483>.

Swift SVN r12974
2014-01-26 22:38:45 +00:00
Doug Gregor
e9fdec95fe Put specialized and inherited conformances into an appropriate arena.
This is infrastructure toward allowing us to construct conformances
where there are type variables <rdar://problem/15168483>, which keeps
tripping up library work.

Swift SVN r12899
2014-01-24 04:13:17 +00:00
Doug Gregor
159dd088d8 Move the "type conforms to protocol" cache into the ASTContext arena.
This fixes an awful nondeterministic memory smasher involving cases
where the type checker checks whether a type involving type variables
conforms to a given protocol. The checks were cached in an
ASTContext-level data structure, but the keys involved
constraint-checker-allocated types. Stale entries in the cache caused
all manners of unreproducible weirdness, almost surely including
<rdar://problem/15715339>, <rdar://problem/15736793>,
<rdar://problem/15768325>, and probably others.

Swift SVN r12898
2014-01-24 04:13:15 +00:00
Jordan Rose
fd48fb3144 Add a mode to Module::forAllVisibleModules that includes private imports.
Also, remove the mode that left the current module out of the callback.
That's easy enough to check for.

No functionality change yet, but groundwork for the next commit (as well
as some possible uses in LLDB).

Swift SVN r12616
2014-01-20 23:25:04 +00:00
Argyrios Kyrtzidis
90fa27f1b6 [AST] Introduce Module::isSystemModule() which is rather self-explanatory.
Swift SVN r12474
2014-01-17 07:33:49 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Doug Gregor
7b0783f985 Move the "gather all substitutions" operation into the AST. SILGen also needs it.
Swift SVN r12142
2014-01-10 22:32:51 +00:00
Jordan Rose
ac2a9c06da When looking for conformances, make sure to check inherited conformances too.
Previously, if we were looking for, say, ForwardIndex conformance on Int,
we would see that Int is a BidirectionalIndex, and that BidirectionalIndex
refines ForwardIndex...but we'd have no way to get a conformance from
BidirectionalIndex (since it's not really BidirectionalIndex that conforms
to ForwardIndex, but rather Int-via-BidirectionalIndex). Change
Module::lookupConformance's helper findExplicitConformance to actually keep
conformance records around and walk those instead of just looking at the
ProtocolDecl's list of adopted protocols.

I don't have a minimal test case for this, but it fixes
<rdar://problem/15691181>, which allows DictionaryIndex to just adopt
BidirectionalIndex and have the ForwardIndex part be inferred. The problem
manifested as a crash in test/stdlib/Dictionary.swift, which just uses a
Dictionary in very basic ways, so I imagine we'll notice if this regresses.

Swift SVN r11521
2013-12-20 22:41:41 +00:00
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Argyrios Kyrtzidis
93c15bed50 [AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing.

Swift SVN r11338
2013-12-16 01:26:36 +00:00
Doug Gregor
07c0793e30 Construct the type witnesses of SpecializedProtocolConformance lazily.
A SpecializedProtocolConformance intentionally contains all of the
information we need to synthesize the type witnesses from the
underlying (generic) conformance. Do so lazily rather than eagerly,
because we won't always need all of them.

As a nice side effect, we no longer need to serialize the witnesses of
these specialized protocol conformances, so we can save some space in
the Swift module file.


Swift SVN r11303
2013-12-14 06:20:44 +00:00
Doug Gregor
1b161ff043 Eliminate ProtocolConformance::getTypeWitnesses().
Swift SVN r11301
2013-12-14 05:19:18 +00:00
Dmitri Hrybenko
374aa1d57c AST printing: when printing module interface, explode PatternBindingDecls
The exact pattern that was used to declare a variable is not important from the
module interface point of view.


Swift SVN r11231
2013-12-13 02:19:04 +00:00
Dmitri Hrybenko
11ccb38e06 AST printer: use getDisplayDecls() to find a list of decls to print.
We are still not completely correct in determining which extensions to print,
will fix in future patches.


Swift SVN r10960
2013-12-07 00:54:05 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
5dda63aa82 Remove LoadedModule, and strip ModuleLoader down to just loading things.
Now that everything is done in terms of FileUnits, we don't need LoadedModule
anymore, and now that FileUnits just use virtual dispatch, we don't need to
indirect through ModuleLoader to distinguish them.

This doesn't quite simplify as much as it could, because the next change is
going to combine TranslationUnit and Module.

Swift SVN r10836
2013-12-05 01:51:12 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
d0d661164d Move lookupQualified from Module to DeclContext.
Qualified lookup depends not only on the current module but actually the
current file, since imports are file-scoped by default. Currently this only
affects lookup into other modules (e.g. "Foundation.NSString"), but this
could also be used for extension filtering.

This breaks one name resolution test, but the refactoring in the next
commit changes everything anyway and will restore the test.

Swift SVN r10831
2013-12-05 01:51:07 +00:00