Commit Graph

101 Commits

Author SHA1 Message Date
Saleem Abdulrasool
46d684f35f remove usage of BitstreamReader
LLVM SVN r286207 removed the BitstreamReader interface.  Remove the usage of the
type, updating the cursor constructor accordingly.
2016-11-15 17:39:37 -08:00
Huon Wilson
e92b9c2fc1 [Serialization] Remove extraneous argument from ModuleFile::readGenericEnvironment. 2016-11-11 15:02:28 -08:00
Huon Wilson
672de8ee9a [Serialization] Remove redundant GenericSignature return. 2016-11-11 15:02:08 -08:00
Huon Wilson
1102cf6643 [AST] Store a GenericSignature in GenericEnvironment.
An environment is always associated with a location with a signature, so
having them separate is pointless duplication. This patch also updates
the serialization to round-trip the signature data.
2016-11-11 14:57:03 -08:00
Doug Gregor
b5511bd3ea [Serialization] (De-)serialize witnesses completely.
The witnesses in a NormalProtocolConformance have never been
completely serialized, because their substitutions involved a weird
mix of archetypes that blew up the deserialization code. So, only the
witness declarations themselves got serialized. Many clients (the type
checker, SourceKit, etc.) didn't need the extra information, but some
clients (e.g., the SIL optimizers) would end up recomputing this
information. Ick.

Now, serialize the complete Witness structure along with the AST,
including information about the synthetic environment, complete
substitutions, etc. This should obsolete some redundant code paths in
the SIL optimization infrastructure.

This (de-)serialization code takes a new-ish approach to serializing
the synthetic environment in that it avoids serializing any
archetypes. Rather, it maps everything back to interface types during
serialization, and deserialization forms a new generic environment
(with new archetypes!) on-the-fly, mapping deserialized types back
into that environment (and to those archetypes). This way, we don't
have to maintain identity of archetypes in the deserialization code,
and might get some better re-use of the archetypes.

More of rdar://problem/24079818.
2016-11-01 17:14:17 -07:00
Roman Levenstein
6c71745453 Use std::function instead of llvm::function_ref for a callback field.
According to the documentation, llvm::function_ref is better suited for function parameters taking closures.
But in this case we need to store a closure in the callback field and then invoke it multiple times. Therefore it is more appropriate to use std::function for this purpose.
2016-10-08 02:53:50 -07:00
Jordan Rose
9dd6308cfb Improve PrettyStackTrace entries, especially around serialization. (#5079)
Two of them are user-facing, with the following sort of message:

    If you're seeing a crash here, check that your SDK and
    dependencies match the versions used to build 'SwiftLib'

Prompted by rdar://problem/28282310, which took a while to figure out.
The added test case is a simplified version of the issue. (Obviously
we'd prefer to not crash here, but that's hard---there's an inherited
conformance that's no longer valid, and there may be generic types
depending on that conformance.)
2016-10-04 16:22:58 -07:00
Slava Pestov
58ceb472fa Serialization: Remove support for serializing GenericParamList from SIL
Now that SILFunctions store a GenericEnvironment instead of a
GenericParamList, we can remove some unused flexibility.
2016-08-28 13:51:38 -07:00
Slava Pestov
1c1ab0b83a AST: Introduce new GenericEnvironment class
A GenericEnvironment stores the mapping between GenericTypeParamTypes
and context archetypes (or eventually, concrete types, once we allow
extensions to constrain a generic parameter to a concrete type).

The goals here are two-fold:

- Eliminate the GenericTypeParamDecl::getArchetype() method, and
  always use mapTypeIntoContext() instead

- Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch adds the new data type as well as serializer and AST
verifier support. but nothing else uses it yet.

Note that GenericSignature::get() now asserts if there are no
generic parameters, instead of returning null. This requires a
few tweaks here and there.
2016-08-28 13:51:36 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Roman Levenstein
89c41ca2d4 [sil-serializer] Do not use RPOT order for serializing SIL basic blocks
My earlier patch started serializing SIL basic blocks using the RPOT order. While it works, changing the existing order of BBs during the serialization may be very surprising for users. After all, serialization is not supposed to transform the code.

Therefore, this patch follows a different approach. It uses the existing order of BBs during the serialization. When it deserializes/parses SIL and detects a use of an opened archetype before its definition, it basically introduced a forward definition of this opened archetype. Later on, when the actual definition of the opened archetype is found, it replaces the forward definition. There is a correctness check at the end of a SIL function deserialization, which verifies that there are no forward definitions of opened archetypes left unresolved.
2016-07-19 13:04:40 -07:00
Jordan Rose
8f820dea2b [serialization] Diagnose loading modules from older Swifts.
...with a better message than the generic "older version of the
compiler" one, when we know it's actually a different version of
Swift proper.

This still uses the same internal module version numbers to check
if the module is compatible; the presentation of language versions
is a diagnostic thing only.

Speaking of module version numbers, this deliberately does NOT
increment VERSION_MINOR; it's implemented in a backwards-compatible
way.

This will only work going forwards, of course; all existing modules
don't have a short version string, and I don't feel comfortable
assuming all older modules we might encounter are "Swift 2.2".

rdar://problem/25680392
2016-04-29 16:25:33 -07:00
Xi Ge
fda0751cae [SourceKit] In interface-gen request, allow clients to send SourceKit an interested USR from which we can infer the group name. 2016-03-23 17:26:44 -07:00
Slava Pestov
a4c50e1c40 Serialization: Serialize default witnesses when serializing a protocol
This will allow SILGen to check if a requirement was witnessed by
its default implementation.
2016-03-17 10:39:34 -07:00
Xi Ge
c84f667676 [Serialization] Serialize the source order of Decls appearing in their original source file.
We used to think the source order is preserved after de-serialization; however, this seems to be
not the case.
2016-03-08 12:18:10 -08:00
Xi Ge
7a3276738b Re-apply "ModulePrinter: Print decls from the same source file near each other."
This reverts commit 1db83907e3.
2016-03-08 12:18:10 -08:00
Xi Ge
1db83907e3 Revert "ModulePrinter: Print decls from the same source file near each other."
This reverts commit a5c9072344 for mysterious bot test failure.
2016-03-07 23:33:23 -08:00
Xi Ge
a5c9072344 ModulePrinter: Print decls from the same source file near each other. 2016-03-07 22:51:50 -08:00
Jordan Rose
e7e0a87db2 Merge pull request #1254 from jrose-apple/Fixnum
Replace uses of llvm::Fixnum with llvm::PointerEmbeddedInt.
2016-02-11 13:06:45 -08:00
Xi Ge
9aa3d01101 [Serialization] Avoid serializing source orders, trust deserialized decls in preserving such order. rdar://24610992
Thank Jordan for suggesting this.
2016-02-11 12:24:38 -08:00
Jordan Rose
36a44cf308 Replace uses of llvm::Fixnum with llvm::PointerEmbeddedInt.
The two types are nearly identical, and Fixnum is only in the Swift branches of LLVM,
not in mainline LLVM.

I do want to add ++ to PointerEmbeddedInt and fix some of this ugliness, but that'll
have to go through LLVM review, so it might take a bit.
2016-02-11 09:52:07 -08:00
Xi Ge
767fba9c92 Rename BriefAndRawComment to CommentInfo. NFC 2016-02-10 19:27:21 -08:00
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