Commit Graph

179 Commits

Author SHA1 Message Date
Xi Ge
98734f588a [Serialization] Serialize and deserialize source order in module doc files. 2016-02-10 17:46:49 -08:00
Xi Ge
329345077b [SourceKit] Add a new query to collect all group names from a module.
Input:
  Request Id: 'source.request.module.groups'
  Required field: 'key.modulename'

Output:
  Array of group names in that module, if any.
2016-02-08 17:22:10 -08:00
Xi Ge
33b4de7ff6 [Serialization] Add grouping information of Stdlib to its module documentation file and deserialize it into ModuleFile.
We currently do not support more sophisticated naming mechanisms; group names are stemmed source file names.
2016-02-05 16:56:41 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -08:00
John McCall
2df6880617 Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be
able to recover the protocol requirement of a conformance
reference even if it's abstract due to the conforming type
being abstract (e.g. an archetype).  I've made the conversion
from ProtocolConformance* explicit to discourage casual
contamination of the Ref with a null value.

As part of this change, always make conformance arrays in
Substitutions fully parallel to the requirements, as opposed
to occasionally being empty when the conformances are abstract.

As another part of this, I've tried to proactively fix
prospective bugs with partially-concrete conformances, which I
believe can happen with concretely-bound archetypes.

In addition to just giving us stronger invariants, this is
progress towards the removal of the archetype from Substitution.
2016-01-08 00:19:59 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
Doug Gregor
7c0c092004 Eagerly update a protocol's "has missing required members" flag.
Rather than plumbing a "has missing required members" flag all the way
through the LazyResolver's loadAllMembers and its implementations,
just eagerly update the "has missing required members" flag in the
Clang importer when it happens. More NFC cleanup.
2015-12-23 13:38:35 -08:00
practicalswift
36d7072013 Remove immediately adjacent repeated words ("the the", "for for", "an an", etc.). 2015-12-21 22:16:04 +01:00
Jordan Rose
babdb9e9f9 Delay loading the witnesses of a protocol conformance.
Apart from being general compile-time goodness, this helps break a
circularity issue involving serialization cross-references and the
Clang importer.

The test is being added to validation-tests because it relies on
several levels of non-laziness in the compiler, all of which we'd
like to fix. It's making sure we don't regress here, but it isn't
actually verifying this change in particular.

rdar://problem/22364953

Swift SVN r31455
2015-08-25 21:47:18 +00:00
Jordan Rose
98ed31fb99 Make -import-underlying-module automatically export that module.
That's how everything behaved anyway. Might as well make it explicit and
stop special-casing it.

I've left in compatibility for modules built with older compilers so that
people using the OS toolchains aren't immediately unable to debug their apps.
As soon as we change the module format in a more significant way, I can take
this out.

Groundwork for rdar://problem/21254367; see next commit.

Swift SVN r29437
2015-06-17 04:47:39 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Doug Gregor
514ef30943 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27880
2015-04-28 20:59:32 +00:00
Doug Gregor
7dafdf873c Revert "(De-)serialization for foreign error conventions."
This reverts r27870. It's causing inexplicable SourceKit failures.

Swift SVN r27875
2015-04-28 17:50:59 +00:00
Doug Gregor
a487a9e345 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27870
2015-04-28 16:00:47 +00:00
Doug Gregor
061795d2bf Revert "(De-)serialization for foreign error conventions."
This reverts commit face8b23dc1b7132039e8b20b96e9fabe4634649.

Swift SVN r27295
2015-04-14 23:37:18 +00:00
Doug Gregor
759346e5b8 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27294
2015-04-14 22:57:44 +00:00
Chris Willmore
2d985c0a5d Revert "(De-)serialization for foreign error conventions."
This reverts commit r27290 due to several test failures in SourceKit.

Swift SVN r27291
2015-04-14 21:40:13 +00:00
Doug Gregor
f1d4293210 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27290
2015-04-14 21:11:28 +00:00
Luqman Aden
f7403e38c0 SILGen shouldn't know about ModuleFile, use FileUnit instead.
Swift SVN r26577
2015-03-26 03:33:41 +00:00
Doug Gregor
8b97f911c6 Reimplement (de-)serialization of protocol conformances.
Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
2015-03-24 06:48:23 +00:00
Jordan Rose
e6c2131bda Check that "@testable import Foo" is only used to import testable modules.
(i.e. modules compiled with -enable-testing)

Part of testability (rdar://problem/17732115)

Swift SVN r26293
2015-03-19 02:20:41 +00:00
Doug Gregor
bce5c20c25 Teach loadAllMembers() implementations to add the members themselves.
The contract for LazyResolver::loadAllMembers() was that the caller
would handle actually adding the members, since it was an iterable
declaration context and could centralize that (simple) logic. However,
this fails in the Clang importer in rare but amusing ways when some of
the deferred actions (e.g., finishing a protocol conformance) depend
on having the members already set. The deferred action occurs after
the member list is complete in ClangImporter's loadAllMembers(), but
before its caller actual set the member list, leaving incomplete
conformances. Fixes rdar://problem/18884272.

Swift SVN r25630
2015-02-28 01:03:41 +00:00
Jordan Rose
c10ed5eef8 [Serialization] Add an extra include.
It seems to be getting picked up from one of the other headers in master,
but not in 602 (locally), so it seems correct to add here.

No functionality change.

Swift SVN r25230
2015-02-12 06:33:15 +00:00
Jordan Rose
dbd3b60f6b [Serialization] Move (Module)Status and validateSerializedAST into a namespace.
Also into a separate file.

Before (swift/Serialization/SerializedModuleLoader.h):
  ModuleStatus
  SerializedModuleLoader::ValidationInfo
  SerializedModuleLoader::ExtendedValidationInfo
  SerializedModuleLoader::isSerializedAST
  SerializedModuleLoader::validateSerializedAST

After (swift/Serialization/Validation.h):
  serialization::Status
  serialization::ValidationInfo
  serialization::ExtendedValidationInfo
  serialization::isSerializedAST
  serialization::validateSerializedAST

No functionality change, just a lot of renaming and a bit of reorganizing.

Swift SVN r25226
2015-02-12 05:32:25 +00:00
Jordan Rose
478fdcf3ab [serialization] Stop recording the full paths to input source files.
There were no clients and it leaks information about the developer's system.
After this commit, there should be no full paths present in framework modules.
(App modules may contain search paths for debugging reasons, as well as a
full or relative path to the bridging header.)

Swift SVN r24851
2015-01-30 19:22:34 +00:00
David Farler
51f8070abe Serialize local types
Local type declarations are saved in the source file during parsing,
now serialized as decls. Some of these may be defined in DeclContexts
which aren't Decls and previously weren't serialized. Create four new
record kinds:

* PatternBindingInitializer
* DefaultArgumentInitializer
* AbstractClosureExpr
* TopLevelCodeDecl

These new records are used to only preserve enough information for
remangling in the debugger, and parental context relationships.

Finally, provide a lookup API in the module to search by mangled name.
With the new remangling API, the debugging lifecycle for local types
should be complete.

The extra LOCAL_CONTEXT record will compressed back down in a
subsequent patch.

Swift SVN r24739
2015-01-27 01:49:54 +00:00
Jordan Rose
8ee17a4d0d Serialize search paths when building an app, for a better debugging experience.
There's also a testing option, -serialize-debugging-options, to force this
extra info to be serialized even for library targets. In the long run we'll
probably write out this information for all targets, but strip it out of
the "public module" when a framework is built. (That way it ends up in the
debug info's copy of the module.)

Incidentally, this commit includes the ability to add search paths to the
Clang importer on the fly, which is most of rdar://problem/16347147.
Unfortunately there's no centralized way to add search paths to both Clang
/and/ Swift at the moment.

Part of rdar://problem/17670778

Swift SVN r24545
2015-01-20 03:02:54 +00:00
Jordan Rose
6de91151e2 Record whether a file contains a main entry point in the serialized module.
This isn't being used for much yet, but it will allow us to tell whether
something is an app target even at the module-merging stage, which is a
better way to tell if something is an app than whether it has a bridging
header.

We'll also need this if we ever take advantage of reusing "partial modules"
(serialized ASTs for other parts of the module that aren't affected by the
current source file) for compiling source files in incremental builds;
unfortunately that's unlikely given our dependency model.

Swift SVN r24531
2015-01-19 23:08:57 +00:00
Jordan Rose
6b4dc17038 [Serialization] Serialize and check the target a module was compiled with.
Refuse to load a module if it was compiled for a different architecture or
OS, or if its minimum deployment target is newer than the current target.
Additionally, provide the target triple as part of pre-loading validation
for clients who care (like LLDB).

Part of rdar://problem/17670778

Swift SVN r24469
2015-01-16 02:48:59 +00:00
David Farler
cad9f99929 Revert "Serialize local types and provide a lookup API"
Changing the design of this to maintain more local context
information and changing the lookup API.

This reverts commit 4f2ff1819064dc61c20e31c7c308ae6b3e6615d0.

Swift SVN r24432
2015-01-15 00:33:10 +00:00
David Farler
fab3d491d9 Serialize local types and provide a lookup API
rdar://problem/18295292

Locally scoped type declarations were previously not serialized into the
module, which meant that the debugger couldn't reason about the
structure of instances of those types.

Introduce a new mangling for local types:
[file basename MD5][counter][identifier]
This allows the demangle node's data to be used directly for lookup
without having to backtrack in the debugger.

Local decls are now serialized into a LOCAL_TYPE_DECLS table in the
module, which acts as the backing hash table for looking up
[file basename MD5][counter][identifier] -> DeclID mappings.

New tests:
* swift-ide-test mode for testing the demangle/lookup/mangle lifecycle
of a module that contains local decls
* mangling
* module merging with local decls

Swift SVN r24426
2015-01-14 22:08:47 +00:00
Argyrios Kyrtzidis
b11d990818 Avoid APIs that return a new ASTContext-allocated array every time you call them.
Have them fill out a vector provided by the caller instead.

It is very easy to have callers just go through the array, thus wasting memory, as
the clang importer ended up doing.
The caller should be the one deciding if the array must be copied in ASTContext or not.

Swift SVN r23472
2014-11-20 06:33:27 +00:00
Doug Gregor
b27e88b70b Record Objective-C method lookup tables in Swift modules.
Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
2014-11-11 00:19:03 +00:00
Jordan Rose
9d9f9ef150 Re-apply "[serialization] Reject loading a module with the wrong case."
This included a test that failed on case-sensitive filesystems. Test fixed.

(Aside: Why not just have this fail with "no such module"? Why use a different
error? Because even if "import FOO" picks up a module named 'Foo', there may
actually be a module named 'FOO' on the system (in another folder), and we
should be able to find that. Fixing that is tracked by rdar://problem/18691936.)

rdar://problem/15632996 (again)

Swift SVN r22856
2014-10-21 00:30:09 +00:00
Dave Abrahams
7eb173e487 Revert "[serialization] Reject loading a module with the wrong case."
This reverts commit r22818, which caused
to fail.

Swift SVN r22822
2014-10-18 01:02:20 +00:00
Jordan Rose
5aa27cea08 [serialization] Reject loading a module with the wrong case.
Due to case-insensitive filesystems, "import foundation" can result in the
overlay module for Foundation being loaded. Everything is confused later on
because the (wrong) module name is used in manglings, leading to all sorts
of issues.

This is not the right fix for the problem, because a user really is allowed
to have modules named "foundation" and "FOUNDATION" and "Foundation" coexisting
on their system. To do that we'll want to check the actual case of a
.framework bundle or .swiftmodule file on disk and make sure it matches before
even trying to load the file. But this is a good sanity check anyway.

rdar://problem/15632996

Swift SVN r22818
2014-10-17 21:48:03 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
d3a9e58133 Use Nothing instead of {} to initialize Optionals.
In preparation for the switch to llvm::Optional, which has an explicit
default constructor.

Swift SVN r22470
2014-10-02 18:51:33 +00:00
Doug Gregor
e0afb13abb Remove the APINotes library; it lives in Clang, now.
Swift SVN r22286
2014-09-25 18:48:43 +00:00
Jordan Rose
9aed764daa Re-apply "Verify deserialized Swift decls as well as imported Clang decls."
Swift SVN r22248
2014-09-24 00:53:36 +00:00
Jordan Rose
06986b7dca Re-apply the series of commits to remove redundantly-serialized conformances.
I can't actually reproduce the buildbot failure that happened last night, so
hopefully it will (a) happen again, so I can investigate, or (b) not happen
again.

Swift SVN r22230
2014-09-23 20:50:51 +00:00
John McCall
16cb523c3a AST support for accessors.
Swift SVN r22228
2014-09-23 20:34:19 +00:00
Dmitri Hrybenko
45c2005c9d Revert the series of commits to remove redundantly-serialized
conformances (22195 to 22199).

It broke tests:

Failing Tests (4):
   Swift :: Interpreter/SDK/Foundation_NSString.swift
   Swift :: SIL/Serialization/deserialize_appkit.sil
   Swift :: SIL/Serialization/deserialize_foundation.sil
   Swift :: stdlib/NSStringAPI.swift

Swift SVN r22214
2014-09-23 11:40:23 +00:00
Dmitri Hrybenko
fec622de0a Revert "Verify deserialized Swift decls as well as imported Clang decls."
This reverts commit 22200.  It broke building PerfTestSuite:
<rdar://problem/18423171> crash in type checking

Swift SVN r22209
2014-09-23 10:13:03 +00:00
Jordan Rose
a49874afb5 Verify deserialized Swift decls as well as imported Clang decls.
Like the Clang decls, this happens at the end of the type-checking, just as
a simple walk through the loaded decls of the loaded modules. This caught
all of the issues in this commit series and will hopefully keep us honest in
the future.

(By the way, we don't verify right when we return a deserialized decl for the
same reason we don't verify right when we return an imported decl: parts of
the decl may be delayed, and (a) we don't want to force things to be imported
or deserialized sooner than necessary, yet (b) we want to verify as much as
possible.)

rdar://problem/16968891

Swift SVN r22200
2014-09-23 02:06:27 +00:00
Jordan Rose
eea6c17456 [Serialization] init_existential should reference existing conformances.
Part of a series of commits to remove redundantly-serialized conformances.

Swift SVN r22195
2014-09-23 02:06:20 +00:00
Doug Gregor
3119e6d345 Remove the tables that track the types that conform to "known" protocols.
The type checker no longer needs them.


Swift SVN r22137
2014-09-19 16:41:26 +00:00