Commit Graph

971 Commits

Author SHA1 Message Date
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
Jordan Rose
61d3b0d4ec [ClangImporter] Avoid unneeded copy for getExportedModuleName
std::string -> StringRef of long-lived backing storage.

No functionality change.
2019-03-21 15:16:21 -07:00
Jordan Rose
1bec714519 [Serialization] Recover when a typealias can't be deserialized (#23419)
We already detected when a typealias /changed/ incompatibly; being
unable to deserialize it at all is just a very dramatic version of
that, right?

https://bugs.swift.org/browse/SR-9811
2019-03-19 16:45:57 -07:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Jordan Rose
4db46b07b6 [Serialization] Make the input/output of a helper lambda clearer
It still has side effects, and it's still a lambda rather than a
helper function because it's not used anywhere else, but `[&]`
captures in helper lambdas make me nervous (as opposed to callback
lambdas).
2019-02-22 09:01:42 -08:00
Jordan Rose
fff69c9df6 [Serialization] Unify ExistentialMetatype and Metatype deserialization 2019-02-22 09:01:42 -08:00
Jordan Rose
da9fa9eb64 [Serialization] Move the rest of the type layouts into TypeDeserializer 2019-02-22 09:01:40 -08:00
Jordan Rose
0297d8fc3d [Serialization] Move one type's deserialization into a method
...to prove it can be done.
2019-02-22 08:59:36 -08:00
Jordan Rose
cdadaad9b5 [Serialization] Push caching of deserialized types out of helper class
Decls need to do this to avoid re-entrancy issues, but it turns out
types are simpler. I left a dummy "result" variable in the minimize
churn, since I'm going to move all the cases into their own functions
anyway.
2019-02-22 08:59:36 -08:00
Jordan Rose
23fdccc373 [Serialization] Start getTypeChecked() -> TypeDeserializer
Like I just did for DeclDeserializer. This one adds the new class and
moves most of getTypeChecked() into it, but doesn't yet split anything
up.
2019-02-22 08:59:33 -08:00
Joe Groff
64488b19f9 Serialization: Rework serialization of nested archetypes.
Explicitly serialize the parent archetype so that it can be any kind of root archetype.
2019-02-20 12:53:18 -08:00
Jordan Rose
b577838fa9 [Serialization] Collapse prefix/postfix operator deserialization
...using a template.
2019-02-13 20:23:39 -08:00
Jordan Rose
ec95e68ab9 [Serialization] Collapse one level of helper function I didn't need
No functionality change.
2019-02-13 20:23:39 -08:00
Jordan Rose
855ad2ca87 [Serialization] Move all the decl layouts into DeclDeserializer
Now we have a separate function for each serialized declaration kind!
Much cleaner, still NFC.
2019-02-13 20:23:39 -08:00
Jordan Rose
83586c74f0 [Serialization] Move helper lambda into DeclDeserializer
And cache the ASTContext pointer for convenience.
2019-02-13 20:23:39 -08:00
Jordan Rose
9f80d71bfb [Serialization] Move various RAII-based setup into DeclDeserializer
No functionality change.
2019-02-13 20:23:39 -08:00
Jordan Rose
8c062232c5 [Serialization] Make ASTDeserializer stateful, and use that state
...for decl attributes. Also, rename to DeclDeserializer.
2019-02-13 20:23:39 -08:00
Jordan Rose
e5408748cd [Serialization] Move one case in getDeclCheckedImpl out of line
...as a proof of concept. The next commit will move them /all/ out of
line.

(The intent here is to produce better backtraces when not recovering
from errors.)
2019-02-13 20:23:39 -08:00
Jordan Rose
b5a86cf3af [Serialization] Move decl attribute deserialization into new helper
No functionality change.
2019-02-13 20:23:39 -08:00
Jordan Rose
3273f06879 [Serialization] Pull decl deserialization out to a helper class
In preparation for splitting up one big switch into many small
methods. Well, medium-sized methods.

No functionality change.
2019-02-13 20:23:38 -08:00
Jordan Rose
106c470a10 [Serialization] Handle re-export of error enums harder (#21880)
A refinement of Doug's e3207f753c from a year ago to account for
trying to reference an import-as-member error enum /through/ an
overlay when it's in a Clang module using 'export_as'. The problem is
that importing error enums synthesizes a corresponding struct, and
that struct doesn't have a Clang node and so when it isn't found in
the right module the compiler didn't know to allow it anyway.

I know, right?

(Looking at the source change might be simpler than trying to read
the above paragraph.)

I'm still not 100% sure on how this occurred in the original
(Apple-internal) projects hitting this, but I think it's just that we
handle all import-as-member types at once, and the clients were using
something else from a type that contained the error enum, and then
that resulted in the error struct's conformances getting written into
a serialized swiftmodule.

rdar://problem/47152185
2019-01-15 15:02:19 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Ankit Aggarwal
45290837b4 Merge pull request #21110 from aciidb0mb3r/swiftpm-manifest-version
Extend @available to support PackageDescription
2019-01-07 12:20:23 -08:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Jordan Rose
4017416d5e [Serialization] Only allow loading modules during import resolution (#21218)
Very early groundwork for private imports. Should not affect anything
today.
2018-12-12 10:50:20 -08:00
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Slava Pestov
e0c1e819c8 Serialization: Redo generic param xrefs to use GenericSignature
This code used GenericParamList::getOuterParameters() and
DeclContext::getGenericParamsOfContext(). The meaning of the
former is about to change, and the latter is going away.
2018-12-11 23:22:18 -05:00
Ankit Aggarwal
92d09f4e19 Extend @available to support PackageDescription
<rdar://problem/46548531> Extend @available to support PackageDescription

This introduces a new private availability kind "_PackageDescription" to
allow availability testing by an arbitary version that can be passed
using a new command-line flag "-swiftpm-manifest-version". The semantics
are exactly same as Swift version specific availability. In longer term,
it maybe possible to remove this enhancement once there is
a language-level availability support for 3rd party libraries.

Motivation:

Swift packages are configured using a Package.swift manifest file. The
manifest file uses a library called PackageDescription, which contains
various settings that can be configured for a package. The new additions
in the PackageDescription APIs are gated behind a "tools version" that
every manifest must declare. This means, packages don't automatically
get access to the new APIs. They need to update their declared tools
version in order to use the new API. This is basically similar to the
minimum deployment target version we have for our OSes.

This gating is important for allowing packages to maintain backwards
compatibility. SwiftPM currently checks for API usages at runtime in
order to implement this gating. This works reasonably well but can lead
to a poor experience with features like code-completion and module
interface generation in IDEs and editors (that use sourcekit-lsp) as
SwiftPM has no control over these features.
2018-12-08 09:38:40 +05:30
Harlan Haskins
245109d909 Merge pull request #20250 from harlanhaskins/accessorizing
[ParseableInterface] Standardize printing for accessors
2018-11-27 10:31:17 -08:00
Harlan Haskins
a20c31abf1 [Serialization] Add @_hasStorage and private(set) while deserializing 2018-11-26 18:42:02 -08:00
Jordan Rose
1f25ea51d7 Fix two issues with typealiases in protocol extensions (#20654)
- The GenericSignatureBuilder assumed it didn't have to look in
  protocol extensions to resolve member types.

- Serialization was incorrectly filtering out such typealiases when
  trying to resolve a cross-module reference to one.

rdar://problem/46103190
2018-11-26 11:31:12 -08:00
John McCall
6ffeb4d839 [NFC] Add PrettyStackTraceConformance and use it
Also allow the printFooDescription functions to suppress
the trailing newline.
2018-11-15 18:39:35 -05:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Jordan Rose
40cfc458e2 Fix synthesis of 'override' and 'required' on initializers (#20548)
This is actually two separate problems:
- 'override' wasn't getting added to initializers in deserialization
- 'override' was getting added when inheriting a 'required' initializer,
  even though it's normally an error to write that

Needed for parseable interfaces.
2018-11-13 16:54:53 -08:00
Pavel Yaskevich
bce1ba5f37 [AST] Remove @autoclosure flag from function type ExtInfo 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
0857611fa0 [Serialization] Add @autoclosure to parameter decl serialization format 2018-11-10 11:59:28 -08:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Jordan Rose
4539dbfd06 [Serialization] Simplify the representation of GenericParamLists (#20446)
Now that we don't store requirements in the GenericParamList, there's
no reason to use trailing records to list out the
GenericTypeParamDecls.

No functionality change.
2018-11-09 14:17:30 -08:00
Jordan Rose
4270bddaeb Verify that a GenericTypeParamDecl's depth and index are correct (#20445)
Re-applied after fixing a bug in Serialization where the DeclContext
wasn't being set correctly for extensions with nested parameters. I
was unable to come up with a reduced test case, but the CoreStore
project in the source compatibility suite was failing without the
Serialization change, and now it isn't.
2018-11-09 08:58:55 -08:00
Arnold Schwaighofer
963c64e3e7 Add @_private(from: "SourceFile.swift") imports
A module compiled with `-enable-private-imports` allows other modules to
import private declarations if the importing source file uses an
``@_private(from: "SourceFile.swift") import statement.

rdar://29318654
2018-11-08 08:00:47 -08:00
Arnold Schwaighofer
b102c7f6b4 Parser/Sema/SILGen changes for @_dynamicReplacement(for:)
Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
2018-11-06 09:58:36 -08:00
Jordan Rose
3455510300 [Serialization] Encode depth for cross-refs to generic parameters
Otherwise, we can't represent a cross-reference to generic parameters
in a parent type /when used in an extension/.

https://bugs.swift.org/browse/SR-9084
2018-10-26 16:51:44 -07:00
Jordan Rose
14d4235b57 [Serialization] Fast lookup of nested types in modules with overlays (#20024)
Previously, the fast path for nested types only worked when the nested
type was defined in a Swift module or a Clang module without an
overlay; this is because it was originally designed to fix circularity
issues when merging partial modules for a single target. By having a
Swift overlay module pass through requests for nested types to the
underlying Clang module, we get the fast-path behavior in more cases.
(The one case where it /won't/ kick in is if the overlay has a nested
type that shadows a nested type from the Clang module, but that's
probably pretty rare!)
2018-10-24 18:56:55 -07:00
Mark Lacey
703341239b Add support for multiple designated types for an operator declaration.
Add parsing, type checking, serialization, and deserialization support
for specifying multiple types as "designated" for operator lookup for
a given operator declaration.

The constraint solver still considers only the first type when
deciding the order to attempt the elements of a disjunction, so this
doesn't really change behavior yet.
2018-10-09 23:54:01 -07:00
Mark Lacey
5094376677 Do not restore the precedencegroup name when deserializing them.
We only need to have the identifier during type checking of operator
declarations, so we do not need to restore it from the
PrecedenceGroupDecl during deserialization. We can just use the
deserialized name from the PrecedenceGroupDecl directly if needed.

This does result in one change in behavior. When printing modules, we
previously didn't print 'DefaultPrecedence' for items that had no
precedence specified, but now we will as seen in the test update for
IDE/print_ast_tc_decls.swift.
2018-10-08 21:19:37 -07:00
Mark Lacey
36284ba377 Extend operator decls to allow any designated nominal type for lookup.
Rather than limiting this to protocols, allow any nominal type.

Rename -enable-operator-designated-protocols to
-enable-operator-designated-types to reflect the change.
2018-10-06 17:02:31 -07:00
Harlan
2c86e3249c [InterfaceGen] Print property initializers in resilient, fixed-layout types (#19619)
Augment the ASTPrinter to print the name and text of initializer expressions if
a property has an initializer and the type is @_fixed_layout and resides in a resilient module, and serialize the text for partial modules.

With this change, all .swiftinterface files in the project (except for SwiftLang) compile to swiftmodules on macOS.

rdar://43774580
rdar://43812188
2018-10-05 18:21:46 -07:00
Slava Pestov
3b203a520b Serialization: Don't serialize requirement environment for witnesses
Generic environments and archetypes can be expensive to deserialize
if they involve a generic signature not seen before.

Also, canonicalize the witness substitutions to eliminate type
aliases, and map them to interface types, which again are cheaper
to deserialize.
2018-09-27 22:16:17 -07:00
Slava Pestov
8ddd2c02c4 Serialization: Serialize both the substituted and unsubstituted type for a NameAliasType 2018-09-14 14:31:46 -07:00
Harlan
665db876ea [InterfaceGen] Print bodies of inlinable functions in textual interfaces (#19224)
* Introduce stored inlinable function bodies

* Remove serialization changes

* [InterfaceGen] Print inlinable function bodies

* Clean up a little bit and add test

* Undo changes to InlinableText

* Add serialization and deserialization for inlinable body text

* Allow parser to parse accessor bodies in interfaces

* Fix some tests

* Fix remaining tests

* Add tests for usableFromInline decls

* Add comments

* Clean up function body printing throughout

* Add tests for subscripts

* Remove comment about subscript inlinable text

* Address some comments

* Handle lack of @objc on Linux
2018-09-14 10:23:15 -07:00