Commit Graph

11880 Commits

Author SHA1 Message Date
Slava Pestov
783ea28f1a AST: Change AutoClosureExpr::isThunk() to getThunkType() 2020-02-26 23:09:54 -05:00
Arnold Schwaighofer
c1edc2c31c Merge pull request #30050 from aschwaighofer/irgen_enable_type_layout_based_value_witnesses
IRGen: Enable TypeLayout based value witness generation
2020-02-26 06:59:10 -08:00
Holly Borla
3032dbd210 [Serialization] Implement serialization/deserialization for the typeEraser
attribute.
2020-02-25 19:53:25 -08:00
Hamish Knight
63e4ec6bdd Merge pull request #30038 from hamishknight/plenty-of-scope-for-requestification
Requestify scoped import validation
2020-02-25 16:40:00 -08:00
Hamish Knight
ab9b6d7e11 Requestify scoped import validation
Move the validation of scoped imports into a
request, and force the request when we're
type-checking a primary file. This has the nice
bonus of no longer running the validation for
secondary files.

The use of `ModuleDecl::getTopLevelModule` also
allows us to correctly retrieve the top-level
module for a Clang submodule, rather than
potentially retrieving the Swift module in a mixed
source project.

Resolves SR-12265.
2020-02-25 13:29:52 -08:00
Arnold Schwaighofer
f6651d6d45 IRGen: Enable TypeLayout based value witness generation
rdar://51988441
2020-02-25 12:31:30 -08:00
Rintaro Ishizaki
571d09a8a2 Merge pull request #29955 from AnthonyLatsis/operator-diag-qoi
[Parse] Improve recovery from and diagnostics for invalid operator names
2020-02-25 10:11:26 -08:00
Joe Groff
0a318a39f1 Merge pull request #29644 from jckarter/subst-function-type-shakeout
Enable substituted SIL function types
2020-02-25 09:47:10 -08:00
Hamish Knight
d9182af63d [AST] Introduce ModuleDecl::getTopLevelModule
This can be used to retrieve the Swift module
wrapper for a Clang submodule's top-level module.
2020-02-24 20:10:13 -08:00
Xi Ge
853c0f545b Merge pull request #29974 from nkcsgexi/53776566
ABIChecker: ignore accessors with forced static dispatch
2020-02-24 14:25:06 -08:00
Xi Ge
c585fd6748 ABIChecker: contains only opaque accessors for ABI/API checking
rdar://53776566
2020-02-24 12:23:03 -08:00
Joe Groff
cf0e09d9c5 Preserve conformances for upper bound constraints when lowering SILFunctionTypes 2020-02-24 12:14:21 -08:00
Joe Groff
19770e6471 IRGen: Keep substituted function types out of debug info for now. 2020-02-24 12:14:21 -08:00
Joe Groff
1ffafbe77b SIL: Compute result ownership by substituting correct function type 2020-02-24 12:14:21 -08:00
Joe Groff
9c9bf567f7 SIL: Preserve upper bound constraints for substitutions into nominal types.
When extracting substitutions during type lowering, we can't discard protocol constraints
in positions where the substitution is for a nominal type's generic arguments, since associated
types on that protocol may affect the nominal type's ABI.
2020-02-24 12:14:21 -08:00
Joe Groff
5a15d1249c Parse SILFunctionType brackets using consumeStartingLess/Greater.
With the substituted function type syntax, it's easy to end up with multiple angle brackets,
so we should handle token splitting to parse things like `Optional<<A> in (A) -> () for <Int>>`
the expected way.
2020-02-24 12:14:21 -08:00
Holly Borla
9f09add09b Merge pull request #29966 from hborla/type-check-type-eraser-attribute
[Sema] Implement type checking for the `_typeEraser` attribute
2020-02-21 14:12:59 -08:00
Dan Zheng
697c722a5f [AutoDiff] Type-checking support for inout parameter differentiation. (#29959)
Semantically, an `inout` parameter is both a parameter and a result.

`@differentiable` and `@derivative` attributes now support original functions
with one "semantic result": either a formal result or an `inout` parameter.

Derivative typing rules for functions with `inout` parameters are now defined.

The differential/pullback type of a function with `inout` differentiability
parameters also has `inout` parameters. This is ideal for performance.

Differential typing rules:
- Case 1: original function has no `inout` parameters.
  - Original:     `(T0, T1, ...) -> R`
  - Differential: `(T0.Tan, T1.Tan, ...) -> R.Tan`
- Case 2: original function has a non-wrt `inout` parameter.
  - Original:     `(T0, inout T1, ...) -> Void`
  - Differential: `(T0.Tan, ...) -> T1.Tan`
- Case 3: original function has a wrt `inout` parameter.
  - Original:     `(T0, inout T1, ...) -> Void`
  - Differential: `(T0.Tan, inout T1.Tan, ...) -> Void`

Pullback typing rules:
- Case 1: original function has no `inout` parameters.
  - Original: `(T0, T1, ...) -> R`
  - Pullback: `R.Tan -> (T0.Tan, T1.Tan, ...)`
- Case 2: original function has a non-wrt `inout` parameter.
  - Original: `(T0, inout T1, ...) -> Void`
  - Pullback: `(T1.Tan) -> (T0.Tan, ...)`
- Case 3: original function has a wrt `inout` parameter.
  - Original: `(T0, inout T1, ...) -> Void`
  - Pullback: `(inout T1.Tan) -> (T0.Tan, ...)`

Resolves TF-1164.
2020-02-21 09:47:53 -08:00
Arnold Schwaighofer
e8a7b1bd75 Merge pull request #29859 from aschwaighofer/irgen_typelayout_based_value_witness
IRGen: Type layout based value witness generation
2020-02-21 08:24:17 -08:00
Dan Zheng
d7ab0c1547 [AutoDiff] Fix "'alignof' to an incomplete type" error in AutoDiff.h. (#29983)
Using `DenseMap<SILAutoDiffDerivativeFunctionKey, ...>` in a file that includes
AutoDiff.h but not Types.h produced the following error:
```
error: invalid application of 'alignof' to an incomplete type 'swift::SILFunctionType'
```

Fix the error by:
- Including TypeAlignments.h in AutoDiff.h.
- Adding an alignment forward declaration for `SILFunctionType` to TypeAlignments.h.
2020-02-20 22:31:09 -08:00
Owen Voorhees
1b078531ca Merge pull request #29970 from owenv/remove-unused-diags-2
Remove some unused Sema diagnostic messages
2020-02-20 15:09:51 -08:00
Holly Borla
2185f431ad [TypeCheckAttr] Improve diagnostics and candidate notes for typeEraser in
the case where the type eraser has no viable initializers.
2020-02-20 12:50:04 -08:00
Anthony Latsis
1c0c397214 [Parse] Improve recovery from and diagnostics for invalid operator names 2020-02-20 22:11:18 +03:00
Holly Borla
3d18c07640 [TypeCheckAttr] Implement access control checking for the typeEraser
attribute.
2020-02-20 10:57:10 -08:00
David Ungar
e6bbb8d01f Merge pull request #29948 from davidungar/unit-test-users-v5a
[Incremental, NFC] Rearrange code creating `SourceFileDepGraph`
2020-02-20 08:18:21 -07:00
Dan Zheng
f5b40d6705 [AutoDiff upstream] Add SIL derivative function type caching. (#29953)
Upstream https://github.com/apple/swift/pull/29590:
cache `SILFunctionType::getAutoDiffDerivativeFunctionType` results.
2020-02-20 05:17:39 -08:00
swift-ci
5e030b57a2 Merge pull request #29918 from dan-zheng/derivative-attr-diagnostics 2020-02-19 23:26:54 -08:00
David Ungar
b367d2ebec Rename files and classes involved in SourceFileDepGraphConstruction 2020-02-19 23:57:23 -07:00
Holly Borla
f141b4da3c [TypeCheckAttr] Provide better error messages for a typeEraser that
has invalid init candidates.
2020-02-19 21:23:57 -08:00
Dan Zheng
e5e9fce8bf [AutoDiff upstream] Upstream attribute type-checking changes. (#29945)
- Support `@differentiable` and `@derivative` attributes for original
  initializers in final classes. Reject original initializers in non-final
  classes.
- Synchronize tests.
2020-02-19 21:17:45 -08:00
Owen Voorhees
2d1aa2d8ee Remove some unused Sema diagnostic messages 2020-02-19 20:50:59 -08:00
Pavel Yaskevich
8af4f2ddb3 Merge pull request #29493 from LucianoPAlmeida/SR-11421-checked-cast-diag
[SR-11421][Diagnostics] Tailored diagnostic for checked downcast with literals
2020-02-19 17:29:30 -08:00
Holly Borla
ebb727c0a3 [TypeCheckAttr] Allow a type eraser initializer to have more than one
generic requirement.
2020-02-19 17:07:30 -08:00
Alexis Laferrière
0e7029dfb5 Use "SPI group" for the name used in an @_spi attribute 2020-02-19 14:18:11 -08:00
Alexis Laferrière
901392896d [Frontend] Output the private module interface with the SPI info 2020-02-19 14:17:14 -08:00
Alexis Laferrière
2e73cb44fd [Sema] Type-check the use and exposability of SPI decls 2020-02-19 14:17:14 -08:00
Alexis Laferrière
56880d7e70 [Sema] Diagnose the use of SPI on unsupported decls 2020-02-19 14:17:14 -08:00
Alexis Laferrière
501f458879 [AST] Intro service lookupImportedSPIs to find direct SPI imports of a module 2020-02-19 14:17:14 -08:00
Alexis Laferrière
3552f800a9 [Parser] Parse the SPI attribute 2020-02-19 14:17:14 -08:00
Alexis Laferrière
d5969a9f3a [AST] Intro SPI attribute for access control and imports 2020-02-19 14:17:08 -08:00
Brent Royal-Gordon
d842fa3763 Merge pull request #29582 from brentdax/the-most-ambitious-crossover-event-in-history
Cross-Import Overlays
2020-02-19 09:10:55 -08:00
Arnold Schwaighofer
cb2235f8a3 Add code to implement value witnesses based on type layouts
This can be enabled via a flag: -enable-type-layout.

rdar://51988441
2020-02-19 07:12:56 -08:00
Dan Zheng
2c70f0ae6c [AutoDiff] Improve @derivative attribute diagnostics.
Previously, `@derivative` attribute type-checking produced a confusing error
referencing unbound types `T` and `U`:

```
'@derivative(of:)' attribute requires function to return a two-element tuple of
type '(value: T..., pullback: (U.TangentVector) -> T.TangentVector...)' or
'(value: T..., differential: (T.TangentVector...) -> U.TangentVector)'
```

Now, the error is less confusing:

```
'@derivative(of:)' attribute requires function to return a two-element tuple;
first element must have label 'value:' and second element must have label
'pullback:' or 'differential:'
```
2020-02-19 04:48:27 +00:00
Pavel Yaskevich
51257ddf73 Merge pull request #29906 from xedin/eliminate-csdiag
[TypeChecker] Obsolete and remove old diagnostics (CSDiag)
2020-02-18 19:46:54 -08:00
Brent Royal-Gordon
12286197c9 [NFC] Improvements suggested in code review
Thank you, @hamishknight and @varungandhi-apple.
2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
747c50725c Add a warning about redundant cross-import declarations
These are mostly harmless, except that they make the two module names synonymous in qualified lookup. A hard error seems too aggressive for something that could easily be caused by uncoordinated changes to two modules, so warn instead.
2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
d6bccba9b6 Load cross-import overlays 2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
5d74978268 [NFC] Heavily refactor NameBinding
This commit refactors NameBinding.cpp virtually to the point of a rewrite. The goal is to make the import handling code process a struct containing information extracted from an ImportDecl, rather than the ImportDecl itself, so that a future commit can perform the same processing on imports that are not directly represented by an ImportDecl. The result takes more code, but it disentangles a knot of complicated logic into separate threads.

One semi-functional change is that validation of scoped imports (i.e. checking that the declaration actually exists) is now deferred until all of the file’s imports have been processed. Once cross-imports are supported, this will be necessary because scoped imports can select declarations from cross-import overlays, and the full set of cross-import overlays can’t be known until all imports have been seen.

Some comments refer to things that won’t exist until the next commit, like the visibleModules property. I’ll let you in on a litlte secret: I didn’t really do this all in one go.
2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
03832cbc9b [NFC] Allow ImportedModuleDesc to be a DenseMap key 2020-02-18 11:07:12 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00