Commit Graph

1018 Commits

Author SHA1 Message Date
Joe Groff
05c80a8fe9 AST: Avoid instantiating all members when implicit destructors are inserted into classes.
We were accidentally forcing all members of a class to be instantiated in two places:

- by trying to look up an existing destructor decl in the class, and
- by adding the implicit destructor to the class, because addMember needlessly called loadAllMembers.

Fix the former problem by adding a 'has destructor' bit to ClassDecl so we can track whether the implicit destructor needs to be added without querying its members. Fix the latter by making IterableDeclContext::addMember not call loadAllMembers, and making loadAllMembers not barf when it sees existing members in the context.

Together with Jordan and JoeP's changes, this makes many interpreter tests now compile 3-20x faster.

Swift SVN r17562
2014-05-06 20:30:08 +00:00
Doug Gregor
bf4967958a When overriding a method or initializer, require the full names to match.
Do some QoI heroics here so that we get good diagnostics and Fix-Its
when we attempt to override but fail to do so because one picked
different argument names.

Swift SVN r16784
2014-04-25 00:32:42 +00:00
Doug Gregor
82a7f1f87b Improve de-duplication logic for imported Objective-C class initializers.
Before we create a new initializer, check whether it would collide
with existing initializers. If it's better than the existing
initializer, mark the existing one as unavailable; if it's not better,
don't build it.

In support of this, we tweak a few things w.r.t. unavailble
declarations:
  - An unavailable declaration is shadowed by an available one,
  - Don't emit SIL unavailable, imported initializers

This fixes the last problem with <rdar://problem/16509024>.



Swift SVN r16611
2014-04-21 06:26:52 +00:00
Doug Gregor
d35a2f5c94 Allow declarations to be made visible to name lookup before they are added.
NFC so far: the Clang importer will use this to suppress duplicates.


Swift SVN r16600
2014-04-20 20:24:05 +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
Joe Pamer
7245e40825 The type checker collects all overloads for a given function application during the pre-type check phase, but equality conformances (and their associated '==' overloads) may be added to a type lazily during type resolution. This can lead to inconsistent behavior during type checking equality comparisons on imported enumeration types. (rdar://problem/16526249)
Basically, if an imported enumeration case is referenced without qualification as an argument to a '==' application (E.g., "foo.bar == .Baz"), and the enumeration type had not previously been resolved, overloads to '==' will be added to the global scope while performing overload resolution. This means the overloads will be ignored while solving for that application, but will be available for subsequent applications. (So you'll get an "expression does not type check" error the first time around, but not for subsequent applications of '==' to that enumeration type.)

The Equatable protocol is rather lightweight, however, and adding it to imported types directly results in no meaningful overhead to type check performance; we should just add it outright. As things evolve, though, it'll be worth considering how to make the type checker more amenable to lazy declarations.

Swift SVN r16557
2014-04-19 00:12:08 +00:00
Doug Gregor
d80b689c51 Introduce "convenience factory" initializers.
Convenience factory initializers are convenience initializers produced
by importing an Objective-C factory method as a convenience
initializer. The distinction is currently only used to eliminate the
awful layering violation I recently introduced in name lookup, which
was consulting Clang AST nodes directly. It will also be useful in
SILGen.

Swift SVN r16527
2014-04-18 15:34:26 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Doug Gregor
8676ae267a Teach name lookup to shadow factory-method-imported constructors with init-method-imported ones.
There is no way to avoid having both the factory-method-imported
constructor and the init-method-imported constructor show up in the
AST (which could happen in the REPL when subsequent modules are
loaded), so cope with the problem directly. Still, we can do somewhat
better here if we can suppress redundant declarations in the general
case and use "available" in the uncommon case.


Swift SVN r16495
2014-04-18 05:13:09 +00:00
Doug Gregor
b09fbf73b8 Centralize our addition of @objc attributes in the Clang importer.
Swift SVN r16348
2014-04-15 00:35:40 +00:00
Doug Gregor
3b6109e016 Add a member lookup table for classes keyed off an Objective-C selector.
Swift SVN r16346
2014-04-15 00:35:36 +00:00
Jordan Rose
22645d7f97 Add a wrapper type for the union of ArrayRef and LazyMemberLoader+context.
This requires some careful handling since the base of an ArrayRef and the
lazy loading "context data" both have no free bits, but it now works.
(It's essentially a TwoPointerUnion type, just specialized for a particular
pair of two-pointer types.)

No functionality change, except that NominalTypeDecl and ExtensionDecl
are two words smaller.

Swift SVN r15910
2014-04-04 01:17:54 +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
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
bcab632730 When requesting members or protocols from a type declaration, force any delayed members by default. This allows us to pretty-print otherwise unresolved implicit members of imported enums. (rdar://problem/16430343)
Swift SVN r15534
2014-03-26 22:31:02 +00:00
Joe Pamer
eebe1ebf37 When importing external enum types, delay the creation of implicit members and their associated support functions until after the types are actually referenced.
This significantly reduces the amount of overhead incurred when naively importing large external modules without referencing many of its members, which should directly improve response times in the playground. For example, the repro code attached to rdar://problem/16387393 imports Foundation but references none of its members, and with these changes its total compilation time is almost 2.5x faster.

Swift SVN r15479
2014-03-26 01:06:27 +00:00
Dmitri Hrybenko
11fea869c1 Change 'switch' not to fall through between empty cases and always require at
least one statement per case

rdar://16301313


Swift SVN r15266
2014-03-20 11:44:59 +00:00
Doug Gregor
163d2fa24d [Clang importer] Go back to mirroring superclass initializers in subclasses.
When importing an Objective-C class, import all of the initializers in
all of its superclasses. When we have no information about designated
initializers for a class, the initializers come in as subobject
initializers. When we do have information about designated
initializers, we (1) use it to sort out subobject from complete object
initializers in that class, and (2) assume that all initializers from
superclasses are complete object initializers. Overall, this better
matches Objective-C's semantics.



Swift SVN r14841
2014-03-09 08:01:37 +00:00
Doug Gregor
00162dc243 Start emitting stubs for unimplemented designated initializers of the superclass.
When a subclass does not implement a designated initializer of its
superclass, introduce a stub initializer that simply traps. Such stubs
cannot be invoked directly using Swift syntax, but can be invoked
through the Objective-C runtime and from Objective-C code. Catch such
errors rather than allowing them to violate the memory safety of the
language.

Note that we're currently using cond_fail to trap; this will be
improved in the future,


Swift SVN r14839
2014-03-09 07:16:30 +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
Chris Lattner
7bbd9b05a5 Rename DynamicLookup -> AnyObject in a few more comments. This leaves
the DynamicLookupExpr expression and the DeclVisibilityKind::DynamicLookup
enum.  These seem right to me, more descriptive than renaming them AnyObject.
With this, I consider 13327098 to be done.



Swift SVN r14654
2014-03-04 22:17:38 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Doug Gregor
a77d08f5a1 Use inherited initializers rather than cloning for Objective-C classes.
Make Objective-C initializers inherited according to the inheritance
rules we've specified. Prevent the Clang importer from manually
copying all of the initializers from every superclass into each
class. 

This eliminates a ton of extra allocating constructors generated when
importing Objective-C init methods. Now we only generate allocating
constructors for the init methods that are actually declared.

Note that initializer inheritance only actually works for
Objective-C-defined classes. More to come.



Swift SVN r14563
2014-03-02 01:59:54 +00:00
Doug Gregor
d92f1a3158 Inherit complete object initializers when a class supports it.
Teach name lookup to find complete object initializers in its
superclass when the current class overrides all of the subobject
initializers of its direct superclass.

Clean up the implicit declaration of constructors, so we don't rely on
callers in the type checker doing the right thing.

When we refer to a constructor within the type checker, always use the
type through which the constructor was found as the result of
construction, so that we can type-check uses of inherited complete
object initializers. Fixed a problem with the creation of
OpenExistentialExprs when the base object is a metatype.

The changes to the code completion tests are an improvement: we're
generating ExprSpecific completion results when referring to the
superclass initializer with the same signature as the initializer
we're in after "super.".

Swift SVN r14551
2014-03-01 00:51:21 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +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
18923a8e55 Allow name lookup into DynamicSelf and update AST verification to match.
Swift SVN r13973
2014-02-17 02:28:03 +00:00
Jordan Rose
70f8c198dd Add the standard library as a private import for pure Clang modules.
This is needed for the implicit conformances we synthesize. Remove a
hack from TypeCheckConstraints to find swift.~= now that it's available
using normal lookup.

<rdar://problem/15410928>

Swift SVN r13850
2014-02-12 23:57:43 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Doug Gregor
9ccaf820b8 Start making the method overriding rules a bit more sane.
When we type check the signature of a method, determine which method
it overrides (if any) at that time. This ensures that we always have
this information for name lookup (per <rdar://problem/15932845>). 

As part of this, start to make the overriding rules a little more
sane. John has worked out more of the model here, but this patch:
  - Considers an Objective-C method an override of another Objective-C
  method if the selectors match and the type vs. instance-ness of the
  methods match. The method types are checked for consistency
  (subtyping is okay).
  - Diagnoses when a method overrides more than one method from a
  superclass, and
  - Eliminates the "cannot overload method from a superclass"
  diagnostic, which is overly pedantic and oddly limiting.

Note that we lose some amount of checking here. Specifically, we don't
have a good place to check that one has not provided two different
methods that override the same superclass method. The older code did
that (somewhat), and it's not a trivial problem to solve efficiently.

This fixes the part of <rdar://problem/15597226> that is needed for
<rdar://problem/15932845>. It still doesn't handle properties,
subscripts, and undoubtedly other issues.



Swift SVN r13108
2014-01-29 11:08:56 +00:00
Doug Gregor
4eb96f793c Don't perform lookup relative to 'self' outside of a method body.
Swift SVN r12806
2014-01-22 22:46:40 +00:00
Doug Gregor
3cd14d6643 Don't permit DynamicSelf outside the body or return type of a method.
Swift SVN r12761
2014-01-22 19:20:30 +00:00
Jordan Rose
5299a502d0 [ClangImporter] Import class, protocol, and category members lazily.
This still isn't /that/ lazy because a lot of things can force member
deserialization (such as the type-checker generating a DestructorDecl for
every imported class), and we don't do this in a member-granular way just
yet. I don't see any change in testing time, for example.

But besides just being a good thing in general, this perturbs the order
of imported decls enough to fix <rdar://problem/15799697>: we can now
reliably see that there is a -URL:something: function on NSObject that
blocks any properties named 'URL' from being imported as properties.

(Which we don't actually want; see <rdar://problem/15456130>.)

Swift SVN r12685
2014-01-22 00:54:47 +00:00
Jordan Rose
3513184bd7 Pass the decl in question to LazyMemberLoader's callback.
No functionality change, but used in the next commit.

Swift SVN r12684
2014-01-22 00:54:45 +00:00
Chris Lattner
e808c365d0 simplify some code, NFC.
Swift SVN r11798
2014-01-01 20:28:04 +00:00
Chris Lattner
b35858f131 Simplify more cases to use getSemanticsProvidingPattern.
Change Pattern::getBoundName to look through VarPatterns,
which means that the presence of var/let in an argument list no longer 
change the mangling of the function.



Swift SVN r11780
2013-12-31 22:25:43 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Sean Callanan
a1881434c2 Added support to allow LLDB to provide the
location of variables at SIL generation time.
This patch introduces a SILDebuggerClient that
knows how to resolve the locations of variables
that are generated by the debugger.  These
variables have a flag on them that only LLDB
sets.


Swift SVN r11230
2013-12-13 01:43:02 +00:00
Jordan Rose
c2bd6eb2b0 Lazily deserialize members from AST files.
NominalTypeDecls and ExtensionDecls have a list of members. Rather than
eagerly populating that list when the nominal or extension is just referenced,
just include a pointer back to the ModuleFile, so that they can be
deserialized when we actually look into the decl. The design here is
general enough that we could do something similar with imported Clang decls.

Clang is even more lazy here: the on-disk representation is a hash table,
so lookup only forces deserialization of members with the same name. We
probably want that some day, but this might be enough to get by for now.

This is groundwork for loading partial ASTs, where eagerly deserializing
members leads to circular references we're not able to handle.

Swift SVN r11219
2013-12-12 23:31:15 +00:00
John McCall
342a8b35db Parse default-argument expressions in an initializer context.
Swift SVN r11178
2013-12-12 03:36:27 +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
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
Doug Gregor
1082ea51a0 Actual use location information when looking for local variables.
This addresses the bulk of <rdar://problem/15344950>, which involes us
not being able to find local variable declarations in expressions when
the parser didn't pre-bind them for us.

The fix to name lookup itself insures that a case such as 
  case (var a, a)

doesn't allow the second 'a' to find the first.


Swift SVN r9858
2013-10-31 22:56:02 +00:00
Jordan Rose
ec4234bdbc Perform unqualified lookup using the current SourceFile as context.
And, properly treat imports as per-file: when looking up decls through the
TU module, don't pick up every other source file's imports.

This implements our resolution rules:
1. Check the current source file.
2. Check the current module.
3. Check imported modules.

Currently, "import Foo" is treated as a file-private import and
"@reexported import Foo" is treated as a public /and/ module-wide import.
This further suggests that access control is the right tool for re-export
control:

(private) import Foo // current file only
package import Foo   // whole module
public import Foo    // whole world

Swift SVN r9682
2013-10-25 22:21:12 +00:00