Commit Graph

1018 Commits

Author SHA1 Message Date
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
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Dmitri Hrybenko
3bb5ae1ef4 ExternalNameLookup: fix the build and address review comments
Swift SVN r9016
2013-10-08 01:20:49 +00:00
Sean Callanan
03e51df72e Added ExternalNameLookup, a mechanism that allows
UnqualifiedLookup to ask an external source for
names.  There are two phases to this external lookup:

- Before consulting globals in other modules,
  UnqualifiedLookup calls lookupOverrides() to see
  if there are any results that should override the
  results from modules.  (N.b.: these should not be
  able to override names that are locally defined.)

- After consulting globals in other modules,
  UnqualifiedLookup as a last resort calls
  lookupFallbacks() to see if there's anything out
  there at all that could serve that name.  This may
  be more computationally expensive.

These hooks are used by LLDB's expression parser to
resolve names for persistent variables (akin to the
existing $0, $1, ... variables) and variables local
to the current frame.


Swift SVN r9014
2013-10-08 00:58:14 +00:00
Doug Gregor
087e9f7fad Member lookup: finding a superclass doesn't mean we should skip protocols.
Fixes <rdar://problem/15104554>.


Swift SVN r8975
2013-10-07 18:35:02 +00:00
Joe Groff
92cce69e15 AST: Give NominalTypePattern a better AST-level representation.
Instead of relying on the subpattern being a well-formed TuplePattern, let's track our own subelements so we can associate them to properties and validate them ourselves.

Swift SVN r8771
2013-09-30 01:03:18 +00:00
Jordan Rose
15e981964d Define implicit struct constructors on demand and not lazily.
We now do this at lookup, and don't wait to define default constructors.
There's no benefit to waiting.

Swift SVN r8648
2013-09-25 20:08:25 +00:00
Jordan Rose
15bfc8db2b Don't type-check imported decls unless referenced in the source file.
Instead, pass a LazyResolver down through name lookup, and type-check
things on demand. Most of the churn here is simply passing that extra
LazyResolver parameter through.

This doesn't actually work yet; the later commits will fix this.

Swift SVN r8643
2013-09-25 20:08:14 +00:00
Doug Gregor
6dad378b32 Filter out duplicates for DynamicLookup lookups.
Swift SVN r8490
2013-09-20 14:58:27 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +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
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
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Dmitri Hrybenko
d3b0f3ff66 lookupVisibleDecls(): visit patterns in switch 'case' stmts
Fixes a few code completion FIXMEs


Swift SVN r7887
2013-09-04 00:53:44 +00:00
Doug Gregor
04d157427d Make sure that the dynamic lookup table has the right set of members.
Clean up the "can be accessed by dynamic lookup" predicate so that it
checks for a generic context. We no longer need to do the checking in
name lookup, since this means that the dynamic lookup table won't have
anything we can't use (thanks Jordan!). Drop the [objc] allowance for
members of a generic context: it still leaves us with a very weird
case of messaging something when we can't even figure out the type
that we think the object has.

Extend the walk searching for members to include inner classes within
structs, so we get all of the members globally.



Swift SVN r7799
2013-08-30 20:43:34 +00:00
Jordan Rose
a09343e519 Lock down on exports from TranslationUnit modules.
Previously, export control (via [exported]) only applied to modules that
had been serialized -- anything imported in a TranslationUnit was
automatically considered exported. This was done to make life easier when
dealing with the main source file, but it turns out we're going to want to
load other source files as imports, and export control should work there too.

Now, the module iteration methods (Module::forAllVisibleModules,
namelookup::lookupInModule, etc.) can consider the module being passed as
"top-level", meaning its private imports are visible as well. Otherwise,
proper export control is observed even for imported TranslationUnits.

This required a number of test changes involving Swift adapter modules that
forgot to re-export their Clang modules.

Swift SVN r7783
2013-08-30 17:05:32 +00:00
Doug Gregor
91010d102e Dynamic lookup can never find a member of a generic class.
If we allowed dynamic lookup to find a member of a generic class, we
would then have to figure out the generic arguments. Technically, it's
possible that we could deduce the generic arguments from the signature
of the function we found... but it feels unlikely that we'd get the
right answer often enough to make it useful. So don't do that.



Swift SVN r7758
2013-08-29 22:38:53 +00:00
Doug Gregor
9efa20e4eb Improve overload resolution for dynamic lookups.
Unlike normal overload resolution, where we always want the
most-specialized, overriding result, overload resolution for dynamic
lookups favors results in superclasses to those in subclasses, because
we want to put the least requirements on the object
type. Additionally, we don't allow overload resolution to select among
results that come from different classes or protocols.



Swift SVN r7743
2013-08-29 21:07:07 +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
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Dmitri Hrybenko
ca1daac1d0 removeShadowedDecls(): simplify the way we get the type
Apparently, this code was written this way because getCanonicalType() on a
TypeAliasDecl which represented generic parameter used to assert().


Swift SVN r7447
2013-08-22 01:20:15 +00:00
Doug Gregor
e7f5f3da01 Set the type of class/struct/union declarations during type checking.
Previously, we were creating the type corresponding to
class/struct/union declarations as part of creating the declaration
node, which happens at parse time. The main problem with this (at the
moment) occurs with nested nominal types, where we'd end up with the
wrong "parent" type when the type was nested inside an extension
(because the extension hadn't been resolved at the time we accessed
the parent's type). Amusingly, only code completion observed this,
because the canonical type system hid the problem. The churn in the
code-completion tests come from the fact that we now have the proper
declared type for class/struct/union declarations within extensions.

Take a step toward order-independent type checking by setting the type
of a class/struct/union declaration in type checking when we either
find the declaration (e.g., due to name lookup) or walk to the
declaration (in our walk of the whole translation unit to type-check
it), extending the existing TypeChecker::validateTypeDecl() entry
point and adding a few more callers.

The removeShadowedDecls() hack is awful; this needs to move out to the
callers, which should be abstracted better in the type checker anyway.

Incremental, non-obvious step toward fixing the representation of
polymorphic function types. This yak has a *lot* of hair.



Swift SVN r7444
2013-08-22 00:57:38 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Jordan Rose
5486dd4dba Module::forAllVisibleModules never needs to capture its callback.
...so, add a templated overload that ensures that lambdas aren't copied,
so that callers don't need to add an explicit makeStackLambda().

No functionality change.

Swift SVN r7303
2013-08-16 23:32:43 +00:00
Dmitri Hrybenko
67d82f6ca8 Fix 80-cols violation
Swift SVN r7212
2013-08-13 22:53:36 +00:00
Jordan Rose
c4990cfc25 Perform proper shadowing when looking for module-level visible decls.
This makes lookupVisibleDecls use the same code path as qualified and
unqualified lookup. This is more expensive, because it needs to actually
collect a list of /all/ decls in order to properly compute shadowing
information, but this list is not likely to change once the set of imports
has been computed, so we can cache it.

Swift SVN r7168
2013-08-12 18:54:53 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Doug Gregor
0d37a6ee3d Let the type checker decide which protocol members are visible via conforming types.
Deduced associated types are implemented by allowing name lookup into
a type to find the requirements in  the protocols to which that type
conforms. If the protocol conformance produced the witness for the
requirement via deduction (or, eventually, default definitions), we
use the deduced witness; otherwise, the actual declaration within the
type itself is used.

Previously, the AST-level lookup was deciding whether to filter out
protocol requirements based on the conformance information in the
AST. However, this lead to ordering dependencies, because the type
checker doesn't record the conformances in the AST until we've visited
all of the conformances for a given declaration. This lead to an
oddity where one could have one conformance depend on another's
deduced associated type, but only if that conformance was on a later
extension. Fixes <rdar://problem/14685674>.

As part of this, teach the type checker to re-use normal conformances
that get deserialized, rather than creating new ones. Otherwise, we'll
end up with two different copies of the same conformance running
around.


Swift SVN r7075
2013-08-09 01:03:39 +00:00
Jordan Rose
841e3f4bd4 Properly ignore declarations not within the access path of a scoped import.
We now handle this correctly:
  import struct aeiou.A
  import struct aeiou.E

  var _ : aeiou.O // error

Swift SVN r7046
2013-08-08 17:38:24 +00:00
Doug Gregor
c2e5f499ae Correctly compute the set of protocol -> conformance mappings in name lookup.
Getting this wrong caused very, very weird bugs with deduced
associated types. Fixes <rdar://problem/14418181>.


Swift SVN r7018
2013-08-07 23:13:41 +00:00
Jordan Rose
49fc1ba334 Implement proper shadowing rules for unqualified lookup.
This includes proper rules for function overloads (i.e. shadowing by type)
and allowing type lookup to find a type even if it has the same name as
a non-type.

lookupVisibleDecls does not use this behavior yet.

Swift SVN r7016
2013-08-07 22:57:05 +00:00
Jordan Rose
027565a9a9 Implement proper shadowing rules for qualified lookup.
This required a general reworking of the algorithm for qualified name lookup.
Originally, qualified lookup only applied to a module -- not to its exports.
This meant that "Cocoa.NSWindow" would fail, so that was changed to grovel
through all exported modules looking for decls if the top-level module didn't
provide any.

Now, we actually do a breadth-based search, stopping at each level if decls
are provided for a given name. We also now prefer scoped imports to unscoped
imports, so "import abcde" and "import struct asdf.D" will result in a
(qualified) reference to 'D' being unambiguous.

Not working yet:
 - Shadowing for unqualified lookup.
 - Shadowing by types, so that overloads from this module can merge with
   overloads from its exports.

Swift SVN r7014
2013-08-07 22:56:49 +00:00
Dmitri Hrybenko
e93bcda055 Rename SourceManager::rangeContainsLoc() to rangeContainsTokenLoc()
to emphasize its limitations


Swift SVN r6999
2013-08-07 21:05:11 +00:00
Dmitri Hrybenko
686f9ec7fc SourceManager: add functions that compare SourceLocs and SourceRanges
Swift SVN r6994
2013-08-07 20:06:12 +00:00
Jordan Rose
2479f8087b Handle name resolution for qualified access into a module.
This is the Swift equivalent of allowing Cocoa.NSWindow to find
AppKit.NSWindow (or AppKit.NSWindow.NSWindow, really). Some of these
error messages could be improved, but the basic semantics are correct.

Swift SVN r6855
2013-08-02 21:01:03 +00:00
Jordan Rose
9d5c803aff Enable specific-decl imports.
Note that the import kind is not checked yet; this is effectively our old
behavior for "import swift.print".

Infrastructure: move Module::forAllVisibleModules out-of-line, and add
makeStackLambda to STLExtras for using a non-escaping lambda with
std::function.

Swift SVN r6852
2013-08-02 21:00:41 +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
Doug Gregor
4aa4887343 Rework and centralize checking of inheritance clauses.
Detect duplicate and multiple inheritance, clean up diagnostics, and
unify the code that checks the types in the inheritance clause with
the code that sets the superclass and protocol lists.


Swift SVN r6706
2013-07-29 21:23:56 +00:00
Jordan Rose
acce3767db Introduce Module::forAllVisibleModules, and use it where useful.
This iterates over a module's exports, transitively, in an unspecified
but deterministic order. This is useful for any sort of lookup and for
managing transitive inclusion. It also allows us to remove the hack in
Sema for loading a Clang module's adapter module, and just rely on the
previous commit.

Swift SVN r6699
2013-07-29 18:57:04 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Doug Gregor
d0f60ab755 Introduce some encapsulation into ProtocolConformance.
Swift SVN r6648
2013-07-26 18:12:17 +00:00
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Jordan Rose
110d644297 Provide a skeleton for re-exports from serialized modules...
...and use it for shadowed modules (e.g. the Clang module "Foundation"
referenced by the Swift module "Foundation"), so that we can actually
find "NSString" when building AppKit.

Additionally, record shadowed modules as dependencies, so that they can
be loaded when the adapter module is loaded.

Swift SVN r6522
2013-07-23 23:10:13 +00:00
Dmitri Hrybenko
03e6c36676 Code completion: correctly do name lookup into extensions
This change also exposes and fixes a bug where we would improperly filter
shadowed declarations.  removeShadowedDecls() assumed that all decls had the
same name, but when it is used from lookupVisibleDecls(), this is not true.
Thus, we group decls not only by signature, but also by name.


Swift SVN r6460
2013-07-22 18:05:43 +00:00
John McCall
d710c0f5f2 Use the type-in-context in the ExtensionDecl for a generic type.
This is a temporary hack until we properly make these carry
their own generic parameters.

This removes the last valid way to get UnboundGenericTypes in
a checked program.

Swift SVN r6373
2013-07-19 03:10:10 +00:00
Dmitri Hrybenko
722cc29cab Factor out DeclContext::getParentModule(). This cleans up a few places where
similar loops were duplicated.

No functionality changes.


Swift SVN r6353
2013-07-18 20:41:58 +00:00
Dmitri Hrybenko
be7d4ae71d Code completion: fix a few crashes while code completing expressions that have
generic parameter lists


Swift SVN r6349
2013-07-18 18:37:58 +00:00