Commit Graph

137 Commits

Author SHA1 Message Date
Jordan Rose
fc88c5dae6 Operators imported in one source file shouldn't affect another one.
Previously we would cache the results of operator lookup whether or not the
operator we found came from an imported module. Since different source files
can have different imports, it's not correct to automatically share operators
from imported modules with all files in the translation unit.

This still isn't fully correct; the current logic prefers operators from
local imports over operators implicitly available from other source files.

Swift SVN r9683
2013-10-25 22:21:14 +00:00
Dmitri Hrybenko
6895c34741 Code completion: report "semantic context" for every code completion result
Semantic context describes the origin of the declaration and serves the same
purpose as opaque numeric "priority" in Clang -- to determine the most likely
completion.

This is the initial implementation.  There are a few opportunities to bump the
priority of a certain decl by giving it SemanticContextKind::ExprSpecific
context that are not implemented yet.


Swift SVN r9052
2013-10-09 02:08:05 +00:00
Manman Ren
fa0acc9328 SIL Serialiation: add implementation to deserialize SIL and a wrapper class
SerializedSILLoader to hold a list of SIL deserializers.

Also add an intial implementation of a linking pass that is run right after
SILGen to link the declaration of SILFunction to the actual definition in
the serialized module.

We add two blocks to the serialized module: a sil index block that
maps identifier to a function ID and also holds a list of function offsets,
and a sil block for the actual SILFunctions. We can probably use subblock
instead of two top-level blocks.

The serialization/de-serialization of the function hash table and the function
offsets are implemented. But we are missing handling of types (see FIXME in
the code).

ModuleFile::Serialized is made public to be used by SIL deserializer, as well
as ModuleFile::getType.

The SIL deserializer holds a pointer to the ModuleFile, it gets the sil cursor
and the sil index cursor from the ModuleFile. The other option is for SIL
deserializer to find the start of the two sil blocks within itself, thus having
less coupling with ModuleFile.

No testing case yet because we are missing handling of types.


Swift SVN r8206
2013-09-13 17:44:41 +00:00
Manman Ren
ddd7fb4d46 SIL Serialiation: add implementation to serialize SIL basic block and a
few SIL instructions types.

This will be tested when we have a SIL deserializer. Testing cases covering
each implemented SIL instruction will be added.


Swift SVN r8094
2013-09-11 17:52:05 +00:00
Argyrios Kyrtzidis
36a469df0b [modules] Introduce Module::getTopLevelDecls() to get the local-in-module top-level decls.
getDisplayDecls() was introduced for ":print_module" and works slightly differently, e.g.
it will return the decls from a shadowed clang module, since we want to display them.

Swift SVN r7909
2013-09-04 20:55:27 +00:00
Jordan Rose
7f20dfd304 Include inner class members in dynamic lookup results.
Per discussion with Doug, there's no reason why this should not work:

  class Outer {
    class Inner {
      func extract() { ... }
    }
  }

  var obj : DynamicLookup = ...
  obj.extract!()

Swift SVN r7763
2013-08-29 23:09:33 +00:00
Jordan Rose
cad735b896 [serialization] Remove FALL_BACK_TO_TRANSLATION_UNIT hack.
As a bring-up hack, the module serializer would write a special record,
FALL_BACK_TO_TRANSLATION_UNIT, if it encountered something it didn't know
how to serialize. This then directed the deserializer to ignore the
contents of the module file and instead reload the original source file.
Now that we can serialize pretty much everything*, though, we don't need
this, and instead we'd rather know where the serialization coverage has
gaps (by asserting).

Swift SVN r7752
2013-08-29 22:05:43 +00:00
Jordan Rose
9b9e669bf7 Add support for :print_module on Clang modules.
This isn't very efficient: it scans every decl in the Clang TU (forcing
deserialization) and filters based on the decl's enclosing module.
Moreover, since getClangModuleForDecl() currently only handles top-level
modules, all submodules get implicitly added to the top-level module...
and will /not/ match an explicit submodule request.

(This is probably close to the behavior we actually want: include decls that
are from modules that are (a) submodules and (b) re-exported by the top-level
module. We do want that extra check, though, and we would want to find things
specifically by submodule.)

Swift SVN r7602
2013-08-26 23:07:54 +00:00
Jordan Rose
eef39ff914 Add a :print_module directive to the REPL.
This is basically the same as doing a :print_decl on every decl in the module,
except that it does not print extensions that come from other modules, and
/does/ print extensions and operators that come from this module.

Does not yet work for Clang modules or the Builtin module.

Swift SVN r7601
2013-08-26 23:07:51 +00:00
Jordan Rose
ee2ed392c7 Hack in a -module-link-name option for autolinking.
In Swift, a module is expected to know which libraries it needs, rather than
having this specified by an external module map. While we haven't quite
designed this yet (frameworks get this for free in Clang, for example),
we can at least provide a simple option for the common case of a module
associated with a single library.

This will probably change in the future, so I left in the more general
deserialization code I was working on before simplifying the use case.
A loaded module can in theory specify any arbitrary frameworks or libraries
as dependencies, not just a single dylib.

Swift SVN r7583
2013-08-26 18:57:48 +00:00
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +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
1faafccd39 [serialization] Pull AST parts of ModuleFile out into new Deserialization.cpp.
This separates the concerns of "deserialization the AST structures" from
"reading and accessing a module file".

No functionality change.

Swift SVN r7338
2013-08-19 22:45:13 +00:00
Jordan Rose
2c7858bfb2 Add an entry point for id-style lookup of a known name.
This will be used to resolve properties and method calls on objects with
dynamic-lookup ("id") type. For now, this is tested in swift-ide-test
by using the -dynamic-lookup-completion option and providing a
-code-completion-token value.

Caveats/TODOs:
- As before, since we're using the global method pool, this isn't scoped by
  module. We could do a per-module filter, but I don't know if that will
  actually buy us much.
- Again, Clang's method pool does not include methods from protocols.
- Lookup by selector name cannot find properties with a customized getter
  name. <rdar://problem/14776565>
- The Clang-side method pool is keyed by selector, but Swift wants to look
  things up by method name, which maps to the first selector piece, so we
  end up having to do a scan of all the selectors in the pool.

Swift SVN r7330
2013-08-19 21:33:33 +00:00
Doug Gregor
6c80f64c6e Diagnostic circular class inheritance.
Break cycles agressively when we find circular class inheritance. The
stronger AST invariants prevent us from having to check for loops
everywhere in the front end.


Swift SVN r7325
2013-08-19 15:31:13 +00:00
Doug Gregor
64f178a016 Reimplement circularly check for protocol inheritance.
First, make it actually check for cycles properly. Second, pull it
into the checking of the protocol itself, rather than keeping it as a
separate pass that happens too late to be useful. Finally, put the
unchecked/checking/checked bits into the AST to avoid having to keep a
separate DenseMap just for this purpose. Fixes <rdar://problem/14750346>.


Swift SVN r7324
2013-08-19 14:50:29 +00:00
Jordan Rose
2241086363 Add lookupClassMembers for use in id-style dynamic lookup.
With this, we can now get a list of all class members* available in the
current translation unit, which will be necessary for doing id-style
dynamic lookup (inferring which method you're referring to when the base
type is some magic "dynamic lookup" type).

* Including members of protocols, since a class we don't know about could
have implemented the protocol.

Since there is no code currently using this, I've added a new mode to
swift-ide-test to just dump all class members -- what will eventually
happen when you code complete on a dynamic lookup type. This mode will
go away once the other pieces of id-style lookup are in place.

Swift SVN r7287
2013-08-16 20:22:14 +00:00
Jordan Rose
cf6bb91b20 [serialization] Serialize a table of all class members, by name.
This will be used for id-style lookup.

Swift SVN r7286
2013-08-16 20:22:07 +00:00
Jordan Rose
d8c3302552 [serialization] Check cyclic dependencies for typealiases better.
Deserializing a typealias's underlying type can lead to us trying to
deserialize the alias again. When we get back to the outer request,
check to see if there was an inner request, in which case we don't need
to do anything else.

<rdar://problem/14757837>

Swift SVN r7280
2013-08-16 17:50:23 +00:00
Jordan Rose
95ff29b6e2 Make deserialization of known protocol adopters lazy.
...by adding a new callback to ModuleLoader: loadDeclsConformingTo.
This is used only when the type checker doesn't have enough contextual
information to resolve an expression involving a literal, so it's
possible many *LiteralConvertible types will never be loaded.

Deserialization of types with conversion methods is still eager, since
there's no easy hook to tell when they're needed, but the list has been
renamed to refer to any decls that need to be eagerly deserialized, in
case we need it for other purposes in the future.

This probably won't help much in a real program, but it cuts the test
run time by about 5-10% in my build.

Swift SVN r7268
2013-08-15 18:43:40 +00:00
Jordan Rose
5ce857c45c Only record conformances to known protocols, and include them in modules.
This is really two commits in one: first, change the AST and TypeChecker
to only track conformances to known protocols, and second, make sure we
can deserialize decls that conform to known protocols on demand. The
latter is necessary for the type checker to solve constraint systems that
are not fully constrained, and also requires tracking decls with conversion
methods.

Currently decls conforming to known protocols are eagerly deserialized;
that will change soon to be a new ModuleLoader callback. Decls with
conversion functions will continue to be eagerly deserialized for the near
future.

This fixes the initial regressions in making decl deserialization lazy.

Swift SVN r7264
2013-08-15 17:32:20 +00:00
Jordan Rose
45f37732ba [serialization] Separate extensions out into their own table.
This also makes extension-loading slightly more precise; if asked to
load extensions for some struct Foo, we will load extensions for /every/
struct Foo...but now we won't /also/ load extensions for every /class/ Foo.

Swift SVN r7260
2013-08-15 17:31:51 +00:00
Jordan Rose
bca05dab59 [serialization] Lazily load top-level decls, extensions, and operators.
This switches from simple lists of decls to name-based on-disk hash tables,
which allows decls to be loaded lazily when doing simple lookup (but not
code completion, at least not yet).

The on-disk hash table implementation is borrowed from Clang; eventually
it will be pushed down to LLVM's Support library. (Fortunately the
implementation is header-only.)

This breaks a few tests that rely on magic protocols like
IntegerLiteralConvertible, because the type checker won't have seen the
types that conform to those protocols yet. This will be fixed by doing
an additional "hey, modules, got any of these?" lookup.

Swift SVN r7259
2013-08-15 17:31:44 +00:00
Doug Gregor
411233da5a Eliminate the "pre-check protocol" pass from the type checker.
Teach the ArchetypeBuilder how to use callbacks to get at the
protocols from which a protocol inherits and to which an associated
type conforms, so that we can use the type checker's lazy resolution
here.


Swift SVN r7107
2013-08-09 22:09:07 +00:00
Jordan Rose
88cad52d72 Implement type sugar "T?" for Optional<T>.
- New type representation OptionalTypeRepr.
- New sugared type OptionalType.
- New base type SyntaxSugarType, parent of ArraySliceType and OptionalType.
  These two are the same in a lot of ways.
- The form "T[]?" is forbidden, because it makes "Int[4][2]" oddly
  different from "Int[4]?[2]". The type can be spelled "(T[])?" or
  Optional<T[]>.
- Like Slice, "Optional" is just looked up in the current module. This may
  or may not be the desired behavior in the long run.

<rdar://problem/14666783>

Swift SVN r7100
2013-08-09 21:33:36 +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
Jordan Rose
13e9e94059 Honor [exported] or lack thereof for the imports of serialized modules.
This should complete support for Swift-side export control.

Note that a TU's imports are still all "re-exported" (i.e. returned from
getReexportedModules) whether they are marked [exported] or not. This is
a convenient trick to get lookup in the main source file to look at all
imported modules, but if we allow real multi-TU compilation we'll have to
revisit this.

Swift SVN r7052
2013-08-08 19:09:30 +00:00
Jordan Rose
a35f7cbd4b Thread [exported] through TranslationUnit and the Serialization library.
This still doesn't do anything yet.

Swift SVN r7051
2013-08-08 19:09:21 +00:00
Jordan Rose
42a109674d [serialization] Serialize import access paths, and only the TU's own imports.
Previously, a module contained references to every module listed in the
ASTContext. Now, we actually only encode the imports from the TU itself,
which allows us to include access paths for scoped imports.
This is necessary to implement proper name lookup shadowing rules.

Swift SVN r7013
2013-08-07 22:56:41 +00:00
Jordan Rose
d3b31b8b72 Don't include re-exports in a TU's imported module list.
We can get to these transitively; we should only record what the TU
actually claims to reference.

It turns out that we were still relying on this to force the load of
adapter modules for Clang modules. For now, we just force that up front,
even though currently that also forces the creation of ClangModule
wrappers for all transitive includes.

No intended visible functionality change.

Swift SVN r7012
2013-08-07 22:56:32 +00:00
John McCall
e9b913fb5b Remove LocalStorageType, make it a kind of SILType.
Swift SVN r6968
2013-08-07 00:22:26 +00:00
John McCall
36aa6c2645 alloc_stack needs to return two values like alloc_box.
The current implementation of dealloc_stack in IR-gen is a
no-op, but that's very much wrong for types with non-trivial
local allocation requirements, e.g. archetypes.  So we need
to be able to do non-trivial code here.  However, that means
modeling both the buffer pointer and the allocated address
in SIL.

To make this more type-safe, introduce a SIL-specific
'[local_storage] T' type that represents the required
allocation for locally storing a T.  alloc_stack now returns
one of those in additon to a *T, and dealloc_stack expects
the former.

IR-gen still implements dealloc_stack as a no-op, but
that's now easy to fix.

Swift SVN r6937
2013-08-06 07:31:41 +00:00
Doug Gregor
6fbe6de81a Rework (de-)serialization of generic and inherited conformances.
IdentifierIDs and TypeIDs should be kept distinct. Instead, conflict
DeclID and TypeID, which is acceptable.


Swift SVN r6906
2013-08-05 17:12:39 +00:00
Doug Gregor
1bd583cdf8 [Module file] (De-)serialize inherited protocol conformances.
Swift SVN r6886
2013-08-05 14:29:16 +00:00
Doug Gregor
666213348d [Protocol conformance] Refactor protocol conformance representation.
Factor the ProtocolConformance class into a small hierarchy of
protocol conformances: 
  - "normal" conformance, which provides a complete mapping for the
  explicit conformance of a nominal type (which may be generic) to a
  protocol;
  -  "specialized" conformance, which specializes a generic
  conformance by applying a set of substitutions; and
  - "inherited" conformance, which projects the conformance from a
  superclass to a conformance for a subclass.

In this scheme "normal" conformances are fairly heavyweight, because
they provide a complete mapping. Normal conformances are unique,
because they're associated with explicit conformance declarations
(which cannot be repeated within a module; checking is TBD). Thus, IR
generation will eventually emit them as strong symbols.

"Specialized" and "inherited" conformances occur when we're dealing
with generic specializations or subclasses. They project most of their
members through to some underlying conformance, eventually landing at
a "normal" conformance. ASTContext is responsible for uniquing these
conformances when it sees them. The IR generation model for
specialized conformances will involve runtime specialization of the
underlying witness table; inherited conformances are probably no-ops
from the IR generation perspective.

Aside from being the right thing to do, having small, uniqued
conformances for the specialization and inheritance cases is good for
compile-time performance and memory usage. We're not really taking
advantage of this everywhere we could, yet.

This change uncovered a few existing issues (one known, one not
known), particularly because we're projecting inherited conformances
rather than building new conformances:
  - <rdar://problem/14620454>: protocol witnesses to methods of
  classes need to perform dynamic dispatch. See the
  test/Interpreter/typeof.swift test for an example.
  - <rdar://problem/14637688>: comparing NSString and String with ==
  fails, because they are inter-convertible. I suspect we were missing
  some protocol conformances previously, and therefore accepting this
  obviously-invalid code.



Swift SVN r6865
2013-08-02 22:59:54 +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
f03245a206 Fix up a bunch of filtering-by-decl-access-path.
Mostly cleanup, a few filled-in FIXMEs to filter out decls that don't match
the access path name.

Swift SVN r6850
2013-08-02 21:00:28 +00:00
Joe Groff
f4eed420b3 Store the Module of a ProtocolConformance rather than the decl.
This is all we need for linkage and is easier to reliably recover during deserialization.

Swift SVN r6803
2013-08-01 04:10:52 +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
Jordan Rose
62535fb95c [serialization] Serialize ObjC bit, [iboutlet], [ibaction], [class_protocol].
This should include all of the attributes we care about for the time being.
Only the resilience attributes (not designed) and [force_inline] are left
unaccounted for.

Swift SVN r6767
2013-07-30 23:17:12 +00:00
Doug Gregor
ceaa5e00bf Suggest explicit protocol conformance via Fix-Its.
When we notice that a type implicitly conforms to a protocol but is
not explicitly stated to do so, note this and provide a Fix-It
attaching the conformance to a declaration within the translation
unit, e.g.,

t.swift:28:16: error: type 'S1' does not explicitly conform to protocol 'P'
var p1 : P = S1()
               ^
t.swift:8:8: note: introduce explicit conformance to protocol 'P'
struct S1 : Q {
       ^
             , P



Swift SVN r6760
2013-07-30 22:45:10 +00:00
Jordan Rose
3e7eef56e7 Kill [stdlib] attribute.
Now that we have true serialized modules, the standard library can import
the Builtin module without any special direction (beyond -parse-stdlib),
and anyone can include those modules without special direction.

Swift SVN r6752
2013-07-30 21:27:42 +00:00
Jordan Rose
d6c135291e [serialization] Be defensive in preserving the deserialization cursor's offset.
Add BCOffsetRAII to getDecl() and getType() so that these functions
preserve the current cursor position. This spends an extra save and
restore to avoid accidentally shooting ourselves in the foot by losing
our position (see r6516).

No functionality change.

Swift SVN r6750
2013-07-30 21:10:05 +00:00
Joe Groff
70dbbc806b Store type, protocol, and conforming decl in ProtocolConformances.
This makes ProtocolConformances fully self-identifying so that a ProtocolConformance* pointer alone is enough to identify a conformance as a link entity.

We currently lose the conforming decl during deserialization because trying to deserialize a reference to an ExtensionDecl asserts out. I'll bug Jordan about that.

Swift SVN r6735
2013-07-30 01:26:26 +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
cfe9e0ad37 [Module format] Don't serialize 'inherited' types of any declaration.
The 'inherited' type list of a declaration represents the parsed for
of the inheritance clause, which is now not serialized. The semantic
informance exists in the superclass (when present) and list of
protocols. Future refactoring of the 'inherited' list will make this
more clear.


Swift SVN r6686
2013-07-29 15:23:44 +00:00
Doug Gregor
3d0c2e2612 Record the protocols and superclass for generic parameters.
This allows us to use getProtocols() rather than getInherited()
wherever we're dealing with generic parameters and associated types.


Swift SVN r6683
2013-07-29 14:27:25 +00:00
Doug Gregor
1759210067 (De-)Serialize the protocols from which a protocol inherits.
Switch a few more clients from ::getInherited() to
::getProtocols(). The trajectory here is that ::getInherited() will
turn into something only populated when we've parsed the inheritance
clause, and that "the truth" will be getProtocols(). The former will
cease being serialized once this is the case.


Swift SVN r6661
2013-07-26 23:57:52 +00:00
Doug Gregor
709882c2b8 Capture complete associated type substitution information in the AST.
Previously, we only tracked the mapping from associated types to their
type witnesses. Now, also track the protocol conformances for each of
the requirements placed on the associated types.


Swift SVN r6655
2013-07-26 22:04:53 +00:00
Doug Gregor
532dd646dc Use "witness" rather than "value witness" to mean a non-type witness in the AST/type checker.
The term "value witness" has a very specific meaning in IR generation,
causing unnecessary confusion.


Swift SVN r6650
2013-07-26 18:34:06 +00:00