Commit Graph

103 Commits

Author SHA1 Message Date
Dmitri Hrybenko
35c587aadf Code completion: don't complete associated types on non-metatypes
Swift SVN r16817
2014-04-25 12:46:32 +00:00
Doug Gregor
292dc76420 Remove debugging dumps.
Swift SVN r16574
2014-04-20 01:06:15 +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
Chris Lattner
33eb263a07 use isa instead of dyncast in a boolean context, NFC.
Swift SVN r15950
2014-04-04 18:57:57 +00:00
Jordan Rose
aa6aa72ba1 Add lazy conformances to nominals and extensions.
...and deserialize conformances lazily.

No intended user-visible change.

Swift SVN r15911
2014-04-04 01:17:54 +00:00
Joe Pamer
31bab38eb4 When attempting to obtain the context type of a type extension, we were never taking into account the fact that the extended type could be potentially be unbound.
(This could occur, for instance, via a forward reference to a member defined in an extension to a generic type.)  This problem has been popping up a lot lately, and
was making some of the recent runtime work difficult.  (rdar://problem/16481483)

Swift SVN r15805
2014-04-02 16:48:14 +00:00
Dmitri Hrybenko
0168a70d09 dumpContext(): correctly dump AbstractFunctionDecl context if the type is not
set yet


Swift SVN r15452
2014-03-25 14:41:40 +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
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Chris Lattner
0a88809fb6 now that there is only one caller of getSelfTypeInContext and
getInterfaceSelfType, inline them into their caller.  This
has the nice effect of moving getSelfTypeForContainer into
Decl.cpp instead of being in DeclContext.cpp (which never
made sense to me).


Swift SVN r12984
2014-01-27 06:32:21 +00:00
John McCall
82e192df6e Optimize some generics-related queries on DeclContexts.
Swift SVN r12941
2014-01-24 22:46:21 +00:00
Doug Gregor
88355dd322 Base the implicit 'self' parameter type on DynamicSelf when appropriate.
To get here, make the implicit 'self' parameter a bit more like a
parsed parameter, by giving it a trivial TypeRepr so that pattern
validation will validate the type. This latter piece is important for
DynamicSelf, because we need the interface type of the function to
refer to the implicit generic parameter while the actual type refers
to the archetype.



Swift SVN r12757
2014-01-22 18:36:38 +00:00
Doug Gregor
56b60d9726 Factor "self" type computation into one place within libAST.
Oh, and start creating the implicit generic parameter for
DynamicResult functions.




Swift SVN r12744
2014-01-22 16:03:26 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +00:00
Joe Groff
70de0802e9 AST: Make the @inout-ness of interface types for protocol members consistent with their old types.
There are two places that need to be fixed:

- getSelfTypeForContainer needs to check for a ProtocolDecl context instead of assuming ArchetypeType self == protocol method. Archetypes don't appear in interface types.
- semaFuncDecl's computeSelfType helper needs to have the same special case for protocol contexts as getSelfTypeForContainer.

This will hopefully be tested soon when I can land my next round of SIL interface type changes.

This exposes a problem with Chris's approach to handling the Self of @mutating protocol methods--the fact that they're still @inout manifests to the user if they try to use an uncurried instance method of a generic or existential type. This isn't on the critical path so leave it as <rdar://problem/15821762> for now.

Swift SVN r12312
2014-01-15 04:17:42 +00:00
Chris Lattner
132aca7a46 finish a thought.
Swift SVN r12118
2014-01-10 05:54:53 +00:00
Chris Lattner
96856f2f8e For a complicated set of reasons, protocol methods will be modeled
as taking the "self" receiver as @inout in the requirement funcdecls,
whether they are @mutating or not.  This will allow us to generate better
code, eliminate MaterializeExpr, and have immutable arguments someday.

As such, I think I'm done hacking on this function.  Clean it up and document
its behavior, NFC.


Swift SVN r12117
2014-01-10 05:43:50 +00:00
Doug Gregor
fc00bf6076 Parsing and semantic analysis for delegating initializers.
Swift SVN r11921
2014-01-06 16:33:08 +00:00
John McCall
4355a21a62 Mangle closures using their context and discriminator.
Swift SVN r11885
2014-01-04 04:37:57 +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
Chris Lattner
18a9193452 Redesign how @inout propagation works in the typechecker:
- Switch all the 'self' mutable arguments to take self as @inout, since
   binding methods to uncurried functions expose them as such.
 - Eliminate the subtype relationship between @inout and @inout(implicit),
   which means that we eliminate all sorts of weird cases where they get
   dropped (see the updated testcases).
 - Eliminate the logic in adjustLValueForReference that walks through functions
   converting @inout to @inout(implicit) in strange cases.
 - Introduce a new set of type checker constraints and conversion kinds to properly
   handle assignment operators: when rebound or curried, their input/result argument
   is exposed as @inout and requires an explicit &.  When applied directly (e.g. 
   as ++i), they get an implicit AddressOfExpr to bind the mutated lvalue as an
   @inout argument.

Overall, the short term effect of this is to fix a few old bugs handling lvalues.
The long term effect is to drive a larger wedge between implicit and explicit 
lvalues.


Swift SVN r11708
2013-12-29 04:38:26 +00:00
Chris Lattner
6f7d15dda0 the 'self' argument of a mutable value type method should be @inout(implicit), not @inout.
Swift SVN r11704
2013-12-28 22:56:41 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
9462fca05c Several NFC changes:
- In AST/Decl.cpp, simplify by always setting isMutating to true for 
   ctors/dtors, since mutability only means something to struct/enum 
   methods anyway.
 - in DeclContext.cpp, continue to lvalue qualify the 'self' of protocol 
   methods, this is currently dead.
 - in CSApply, fix logic for some value-type member processing stuff
   to properly handle methods that have a self which is not lvalue 
   qualified. Not exercised yet.


Swift SVN r11650
2013-12-26 01:42:51 +00:00
Chris Lattner
a49dfe2b3a Start setting 'self' as a rvalue instead of an rvalue. First up are
property and subscript getters which have no explicit FuncDecl for 
the getter.  I'm not exactly sure where these come from, but they 
look like something the clang importer is producing in some cases.


Swift SVN r11642
2013-12-25 23:37:29 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Chris Lattner
23d740b740 The type checker is building RequalifyExpr's to strip off the @settable bit
in various unfortunate cases, which is really wrong and causing unpleasantness
for the new mutability model.  However, we can't fix this until the new 
mutability model lands.

To get from here to there, add some assertions to RequalifyExpr expr's ctor 
that are only enabled by the new model, to help me track down and purge these 
infractions.



Swift SVN r11445
2013-12-18 22:55:21 +00:00
Chris Lattner
01be26cd4b Add a new command line option that turns on by-value self arguments for structs
when a method is not declared @inout.


Swift SVN r11386
2013-12-17 17:25:42 +00:00
John McCall
5ae30af77d Don't crash when dumping an AbstractFunctionDecl as a context.
Swift SVN r11378
2013-12-17 04:31:37 +00:00
Doug Gregor
0c4baac6f6 Make the 'self' declaration of a value type constructor be '@inout'.
This removes an oddity in the AST whereby the 'self' declaration
within a value type constructor was not represented as @inout, despite
having @inout semantics in the language.


Swift SVN r11194
2013-12-12 18:31:54 +00:00
John McCall
0bfa86673f Introduce (but don't yet create) a new kind of DeclContext for
various kinds of expressions that appear outside of local
evaluation contexts.

Swift SVN r11176
2013-12-12 03:36:17 +00:00
Argyrios Kyrtzidis
a0403e30a3 [AST] In DeclContext::getDeclaredTypeOfContext() make sure that the extension context
has a resolved TypeDecl to use.

This fixes a crash of a test case on the SourceKit side.

Swift SVN r10999
2013-12-08 20:32:29 +00:00
Joe Groff
5ec46788bd Add interface type helpers to DeclContext.
getInterfaceSelfType gets the interface type of a 'self' parameter outside of the context, like getSelfTypeInContext does for the in-context self type.

getDeclaredInterfaceType gives the declared interface type of a TypeDecl.

getGenericSignatureOfContext returns the dependent generic signature of a decl context.

Swift SVN r10973
2013-12-07 03:00:15 +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
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
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
Adrian Prantl
2edcd17029 [Mangler] Fix a bug in the new Qq mangling that would insert the
innermost DeclContext of the decl that uses the archetype instead of the
actual generic context of the archetype.

<rdar://problem/15453889> Qualified archetypes mangle wrong DeclCtx

Swift SVN r10470
2013-11-14 22:38:32 +00:00
Doug Gregor
84a4c08f1d Factor the computation of the 'self' type into an easier-to-use place.
Swift SVN r9973
2013-11-05 22:51:17 +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
Jordan Rose
2aeba96d53 Use SourceFile in a few more places.
- Local name lookup
- AST verification
- Delayed parsing
- Type checker, for the file kind
- Context of synthesized REPL decls

Swift SVN r9648
2013-10-24 18:59:26 +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
Argyrios Kyrtzidis
efe3d94e6b [AST] Introduce DeclContext::walkContext(), used for ASTWalking a DeclContext.
Swift SVN r8776
2013-09-30 15:43:09 +00:00
Argyrios Kyrtzidis
bded52492e [AST] Introduce DeclContext::getLocalContext(), which returns the first local parent context.
Swift SVN r8775
2013-09-30 15:43:08 +00:00
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Dmitri Hrybenko
e7af4d6c72 Collapse ImplicitClosureExpr into its abstract base class, ClosureExpr
Swift SVN r8280
2013-09-16 18:31:05 +00:00
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +00:00