1627 Commits

Author SHA1 Message Date
Xi Ge
fe27ad35db Serialization: add an option to allow deserializing @_implementationOnly dependencies
In theory, we shouldn't need to deserialize @_implementationOnly dependencies. However,
potential decl recovery issues may bring down lldb if we insist on not importing these
dependencies, resulting in bad user experience as a result. This patch adds an internal
option to allow importing them and it should only be set by lldb and other tools.

rdar://65570721
2020-08-10 13:11:19 -07:00
Harlan Haskins
d67d7ebc0a [Serialization] Look for cross-ref errors inside type errors (#33271)
In #30614, we started consuming XRefNonLoadedModuleErrors while loading
conformances, since a conformance to a type we cannot load usually
indicates we're trying to load a protocol that was declared in an
@_implementationOnly imported module.

We should also consume TypeErrors that we see where the underlying reason
is an XRefNonLoadedModuleError, since they're likely indicators of the
same thing.
2020-08-04 13:04:14 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Michael Gottesman
d2f986739c Merge pull request #32940 from gottesmm/pr-8414ddbc369ed5bb8c0622162de920b962426cf1
[ast] Rename VarPattern -> BindingPattern.
2020-07-18 20:47:21 -07:00
Holly Borla
61cb9a5f4f Merge pull request #32866 from hborla/property-wrapper-autoclosure
[Property Wrappers] Use autoclosure information from CSApply to compute `VarDecl::getPropertyWrapperInitValueInterfaceType`
2020-07-17 09:16:05 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -07:00
Holly Borla
a6c33a9611 [Property Wrappers] Use autoclosure information from CSApply to compute
`VarDecl::getPropertyWrapperInitValueInterfaceType`.
2020-07-13 17:22:29 -07:00
Brent Royal-Gordon
9a838bb654 Differentiate between Swift 5 and “Swift 6” #file
In -swift-version 5 and earlier, #file will continue to be a synonym for #filePath; in a future -swift-version (“Swift 6 mode”), it will become a synonym for #fileID. #file in libraries will be interpreted according to the language mode the library was compiled in, not the language mode its client uses.

Implement this behavior, tied to a frontend flag instead of a language version. We do so by splitting the old `MagicIdentifierLiteralExprKind::File` into two separate cases, `FileIDSpelledAsFile` and `FilePathSpelledAsFile`, and propagating this distinction throughout the AST. This seems cleaner than looking up the setting for the module the declaration belongs to every time we see `File`.

This doesn’t handle module interfaces yet; we’ll take care of those in a separate commit.
2020-07-13 14:06:55 -07:00
Brent Royal-Gordon
0e569f5d9e Add support for #fileID
This temporarily breaks -enable-experimental-concise-pound-file.

fixup adding #fileID
2020-07-13 14:05:13 -07:00
Brent Royal-Gordon
acc01aea03 [NFC] Add MagicIdentifierKinds.def
Extracts the list of magic identifier literal kinds into a separate file and updates a lot of code to use macro metaprogramming instead of naming half a dozen cases manually. This is a complicated change, but it should be NFC.
2020-07-13 14:05:13 -07:00
Dan Zheng
bf47403162 [AutoDiff] Serialize and print @derivative and @transpose accessor kind. (#32839)
Serialize and print the optional accessor kind in `@derivative` and `@transpose`
attributes.

Resolves TF-1293.
2020-07-12 15:04:49 -07:00
Argyrios Kyrtzidis
99c29145b2 [Serialization] Refactor subset of ModuleFile into ModuleFileSharedCore
The difference with `ModuleFile` is that `ModuleFileSharedCore` provides immutable data and is independent of a particular ASTContext.
It is designed to be able to be shared across multiple `ModuleFile`s of different `ASTContext`s in a thread-safe manner.
2020-07-06 00:44:36 -07:00
ematejska
fbec91a1b5 [Autodiff] Derivative Registration for the Get and Set Accessors (#32614)
* initial changes

* Add tests, undo unnecessary changes.

* Fixing up computed properties accessors and adding tests for getters.

* Adding nested type testcase

* Fixing error message for when accessor is referenced but not acutally found.

* Cleanup.

- Improve diagnostic message.
- Clean up code and tests.
- Delete unrelated nested type `@derivative` attribute tests.

* Temporarily disable class subscript setter derivative registration test.

Blocked by SR-13096.

* Adding libsyntax integration and fixing up an error message.

* Added a helper function for checking if the next token is an accessor label.

* Update utils/gyb_syntax_support/AttributeNodes.py

Co-authored-by: Dan Zheng <danielzheng@google.com>

* Update lib/Parse/ParseDecl.cpp

Co-authored-by: Dan Zheng <danielzheng@google.com>

* Add end-to-end derivative registration tests.

* NFC: run `git clang-format`.

* NFC: clean up formatting.

Re-apply `git clang-format`.

* Clarify parsing ambiguity FIXME comments.

* Adding couple of more testcases and fixing up error message for when accessor is not found on functions resolved.

* Update lib/Sema/TypeCheckAttr.cpp

Co-authored-by: Dan Zheng <danielzheng@google.com>

Co-authored-by: Dan Zheng <danielzheng@google.com>
2020-07-01 20:14:58 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Dan Zheng
d3b6b89de6 [AutoDiff] Support multiple differentiability result indices in SIL. (#32206)
`DifferentiableFunctionInst` now stores result indices.
`SILAutoDiffIndices` now stores result indices instead of a source index.

`@differentiable` SIL function types may now have multiple differentiability
result indices and `@noDerivative` resutls.

`@differentiable` AST function types do not have `@noDerivative` results (yet),
so this functionality is not exposed to users.

Resolves TF-689 and TF-1256.

Infrastructural support for TF-983: supporting differentiation of `apply`
instructions with multiple active semantic results.
2020-06-05 16:25:17 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Hamish Knight
437da8ce20 Avoid verifying un-parented GenericTypeParamDecls
When deserializing, we delay parenting
GenericTypeParamDecls until we install the
GenericParamList on the parent declaration, using
a dummy parent of the ModuleDecl until this
happens.

However when deserializing GenericTypeParamTypes,
we don't necessarily get the opportunity to
deserialize the parent, leaving them with the
dummy parent.

We should probably consider not deserializing
GenericTypeParamDecls at all, we currently only do
it to preserve the sugar of the name, this could
be serialized on the type instead.

For now though, adjust the dummy parent to be the
SerializedASTFile, and tell the ASTVerifier to
skip verification for such generic params.
2020-05-28 11:32:12 -07:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
Anthony Latsis
946796ce5b Serialization: Use checked substitution map deserialization for type nodes 2020-05-20 23:40:22 +03:00
Hamish Knight
912baa8a8b [Serialization] Use direct operator lookup for xrefs
We don't need to look at re-exports when resolving
cross references. Luckily the old lookup logic
didn't, but the new logic will. Therefore switch
it over to calling the appropriate request for a
direct operator lookup. In addition, return a
deserialization error instead of silently
returning nullptr if the lookup fails.
2020-05-18 14:33:42 -07:00
Robert Widmann
a021e6ca02 Merge pull request #31461 from CodaFi/right-said-fred
[NFC] Miscellaneous Cleanups to Patterns
2020-05-01 21:41:49 -07:00
Robert Widmann
72807bf284 [NFC] Don't Serialize Pattern::isImplicit 2020-05-01 16:30:00 -07:00
Hamish Knight
b7320cd6d5 [AST] Collapse two arrays into one
Store an array of Located<Identifier> instead of
an array of Identifiers and SourceLocs on
OperatorDecl. This allows us to cleanup
OperatorPrecedenceGroupRequest a little.
2020-05-01 10:38:34 -07:00
Robert Widmann
0342855e50 [NFC] Debride Pattern.h of Implicit Tri-State
Remove all of this in favor of explicit constructors to preserve the one-liners, or distribute the setImplicit() calls to the callsites if necessary.
2020-04-30 22:03:55 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Xi Ge
cbeb758d95 Merge pull request #31062 from nkcsgexi/61833970
AST: teach getOpaqueResultTypeDecl() to get result from serialized AST
2020-04-17 04:37:57 -07:00
Xi Ge
c1e1cbad85 AST: teach getOpaqueResultTypeDecl() to get result for serialized AST
TBD was missing several opaque type descriptor symbols. The root causes
are: (1) the AST API called by TBD doesn't return opaque type decl if
the decl is from a serialized AST; and (2) the access level of opaque
type decl isn't serialized so TBD considers them as internal.

This change fixes both.

rdar://61833970
2020-04-16 22:16:23 -07:00
Alexis Laferrière
2fbc063b2e [Serialization] Note the misc version field of modules on deser. failures
This added information will hopefully help us understand hard to
reproduce deserialization failures.
2020-04-16 13:50:11 -07:00
Suyash Srijan
724f8c23db [Typechecker] Implement SE-0268 Refine didSet Semantics (#26632) 2020-04-09 01:23:15 +01:00
Marc Rasi
7abf8ae305 actually set the lazy resolver 2020-04-07 15:05:27 -07:00
Dan Zheng
83f6714334 [AutoDiff] Start fixing SR-12526.
Start fixing SR-12526: `@derivative` attribute cross-module deserialization
crash. Remove original `AbstractFunctionDecl *` from `DerivativeAttr` and store
`DeclID` instead, mimicking `DynamicReplacementAttr`.
2020-04-06 06:37:23 -07:00
Robert Widmann
b78ed5319b Merge pull request #30800 from CodaFi/erase-install
[Serialization] Lazily Resolve the Eraser Type of @ _typeEraser
2020-04-03 22:32:40 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Brent Royal-Gordon
9878212a2b Merge pull request #30759 from brentdax/i-need-to-see-some-identification
[NFC] Add names of deserialized decls to pretty stack traces
2020-04-02 16:02:46 -07:00
Brent Royal-Gordon
25d3bbd27e [NFC] Add names of deserialized decls to pretty stack traces
Several declarations must be at least partially deserialized before their names can be determined. Add those names to pretty stack traces to make deserialization crashes easier to debug.

We don’t test pretty stack traces, so this doesn’t contain any test changes.
2020-04-01 13:32:55 -07:00
Dan Zheng
96026575c4 [AutoDiff upstream] Upstream serialization changes. (#30720)
Upstream random serialization code from tensorflow branch:
- `SerializedSILLoader::getAllDifferentiabilityWitnesses()`
- Add diff. witness serialization for functions with `inout` parameters.
- `deserializeSILFunctionType`: fix assertion for differentiability kind.
2020-03-30 12:32:16 -07:00
Hamish Knight
d2434e1bf7 NFC: Rename NameBinding to ImportResolution 2020-03-29 18:43:58 -07:00
ematejska
9082dd48b3 [Autodiff upstream] Finishing @transpose attr serialization (#30683)
* Adding @transpose attr deserialization support

* Turning on the transpose serialization test
2020-03-27 16:20:48 -07:00
Alexis Laferrière
9921cd7c1f Merge pull request #30614 from xymus/fix-deser-indexing
[Serialization] Recover from more failures when reading private declarations
2020-03-24 13:45:00 -07:00
Alexis Laferrière
c133437f2c [Serialization] Recover from opaque type related failures
Fixes rdar://60291019
2020-03-24 10:42:16 -07:00
Alexis Laferrière
4e0038f0df [Serialization] Recover from conformances with missing decls
Components of a requirement may be hidden behind an implementation-only
import. Attempts at deserializing them would fail on a 'module not
loaded' error. We only see failures in non-compilation paths, either in
indexing or with tools like ide-test as they try to deserialize
things that are private.
2020-03-24 10:25:02 -07:00
Dan Zheng
a856d59623 [AutoDiff upstream] Add @differentiable attribute serialization. (#30605)
Serialize "is linear?" flag, differentiability parameter indices, and
differentiability generic signature.

Deserialization has some ad-hoc logic for setting the original declaration and
parameter indices for `@differentiable` attributes because
`DeclDeserializer::deserializeDeclAttributes` does not have access to the
original declaration.

Resolves TF-836.
2020-03-24 08:22:56 -07:00
Hamish Knight
a502246f34 [AST] Add OperatorFixity
Use this instead of DeclKind in a few places.
2020-03-23 09:17:58 -07:00
John McCall
ceff414820 Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`.  I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.

Distinguishing the substitutions has two chief advantages over the existing representation.  First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use.  More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.

As an example of the latter, consider the following protocol conformance:

```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```

The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`.  Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way.  With this change, the lowered signature of this witness could be `<T> @substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.

When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods.  This patch does not actually take that step, however; it merely makes it possible to do so.

As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type.  This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.

My plan is to start by producing substituted function types for accessors.  Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of.  They're also used in narrower ways that should exercise less of the optimizer.
2020-03-07 16:25:59 -05:00
Robert Widmann
d494cc8dcb Merge pull request #30109 from CodaFi/lies-more-lies-and-statistics
[Frontend] Clean Up Usage of UnifiedStatsReporter
2020-02-28 10:24:02 -08:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Holly Borla
3032dbd210 [Serialization] Implement serialization/deserialization for the typeEraser
attribute.
2020-02-25 19:53:25 -08:00
Alexis Laferrière
07ade1ddf0 [Serialization] Recover from a missing conforming type in a protocol conformance
We saw this failure with a Clang module imported @_implementationOnly
with synthesized conformances by the ClangImporter. It caused
issues only in sil-opt as it reads all the witness tables.

rdar://problem/58924131
2020-02-21 10:25:18 -08:00
Alexis Laferrière
d5969a9f3a [AST] Intro SPI attribute for access control and imports 2020-02-19 14:17:08 -08:00