Commit Graph

39091 Commits

Author SHA1 Message Date
Doug Gregor
5ac8d769fd [Property wrappers] Allow default initialization to infer a type.
Property wrappers are allowed to infer the type of a variable, but this
only worked when the property wrapper was provided with an explicit
initialization, e.g.,

    @WrapsAnInt() var x   // infers type Int from WrapsAnInt.wrappedValue

However, when default initialization is supported by the property wrapper,
dropping the parentheses would produce an error about the missing type
annotation

    @WrapsAnInt var x

Make this second case behave like the first, so that default initialization
works consistently with the explicitly-specified version.
Fixes rdar://problem/59471019.
2020-03-26 13:44:08 -07:00
Erik Eckstein
93a0dfc578 SILOptimizer: a new small optimization pass to remove redundant basic block arguments.
RedundantPhiElimination eliminates block phi-arguments which have the same value as other arguments of the same block.
This also works with cycles, like two equivalent loop induction variables. Such patterns are generated e.g. when using stdlib's enumerated() on Array.

   preheader:
     br bb1(%initval, %initval)
   header(%phi1, %phi2):
     %next1 = builtin "add" (%phi1, %one)
     %next2 = builtin "add" (%phi2, %one)
     cond_br %loopcond, header(%next1, %next2), exit
   exit:

is replaced with

   preheader:
     br bb1(%initval)
   header(%phi1):
     %next1 = builtin "add" (%phi1, %one)
     %next2 = builtin "add" (%phi1, %one) // dead: will be cleaned-up later
     cond_br %loopcond, header(%next1), exit
   exit:

Any remaining dead or "trivially" equivalent instructions will then be cleaned-up by DCE and CSE, respectively.

rdar://problem/33438123
2020-03-26 19:30:01 +01:00
Holly Borla
febcbf6d1c Merge pull request #30655 from hborla/missing-conformance-operator-ref
[Diagnostics] Support diagnosing references to operators without argument application
2020-03-26 11:13:12 -07:00
Xi Ge
31afb3f692 Revert "TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes"
For clang decls marked with SWIFT_CLASS, these explicit class initializer symbols turn
out to be necessary in the TBD files.

rdar://60857470
2020-03-26 10:46:53 -07:00
ematejska
75691d641e [AutoDiff upstream] Add linear function SIL instructions (#30638)
Add `linear_function` and `linear_function_extract` instructions.

`linear_function` creates a `@differentiable(linear)` function-typed value from
an original function operand and a transpose function operand (optional).

`linear_function_extract` extracts either the original or transpose function
value from a `@differentiable(linear)` function.

Resolves TF-1142 and TF-1143.
2020-03-26 09:41:14 -07:00
Nathan Hawes
28c6845c56 [test] Add indentation regression test.
swift-5.2-branch doesn't indent the contents of var decl accessor blocks if the
var decl is a direct child of an ifconfig decl on swift-5.2-branch. It works
correctly on master after the recent indentation overhaul, but we didn't have
a test covering that specific case.

Resolves rdar://problem/60292681
2020-03-26 09:34:34 -07:00
Pavel Yaskevich
2fa4fbb7a9 Merge pull request #30646 from xedin/rdar-60225883
[CSApply] Support dynamic member lookup as component of key path dyna…
2020-03-26 09:33:12 -07:00
Nathan Hawes
4ccc95f9b2 Merge pull request #30636 from nathawes/cross-import-indexing
[Index] Add index support for cross import overlays.
2020-03-26 09:22:07 -07:00
Pavel Yaskevich
f75996839a Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter" 2020-03-26 09:19:57 -07:00
Rintaro Ishizaki
1985cfdd0b Merge pull request #30652 from rintaro/ide-completion-func-in-closure-rdar60838686
[CodeCompletion] Don't run second pass for decls in closures
2020-03-26 09:12:44 -07:00
Holly Borla
da715f87c5 [Diagnostics] Support diagnosing references to operators without argument
application in MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef
2020-03-26 08:40:32 -07:00
Xi Ge
ffe8a2b74a Merge pull request #30650 from nkcsgexi/60857172
PrintAsObjC: use header path relative to usr/include when importing non-framework headers
2020-03-26 07:59:20 -07:00
Rintaro Ishizaki
7b7599a28d [CodeCompletion] Don't run second pass for decls in closures
For instance:
--
let globalVar = {
    func something(arg: Int) -> Int {
        #^HERE^#
    }
    return something(12)
}()
--
We want to consider this as a top-level completion, not a function body
completion.

rdar://problem/60838686
2020-03-26 00:42:39 -07:00
Xi Ge
ebe0a45583 PrintAsObjC: use header path relative to usr/include when importing non-framework headers
We could assume usr/include belongs to header search paths. If a header
is located in a deeper location inside this directory, we need to print
the additional path components.

rdar://60857172
2020-03-25 23:30:28 -07:00
Anthony Latsis
3b3eadef05 Merge pull request #30488 from AnthonyLatsis/ast-printer-se-0267
[ASTPrinter] Account for contextual where clauses when printing gen. requirements
2020-03-26 07:32:37 +03:00
Nathan Hawes
45dc14a275 [Index][test] Fix test/Index/Store/cross-import-overly.swift to handle units being printed out of order.
c-index-test sorts the units by their file name, which for the modules in
in this test is just [target-triple].swiftinterface-[hash-of-full-output-path]
and so changes depending on where it's run.
2020-03-25 20:51:56 -07:00
Slava Pestov
e06661d0c4 Merge pull request #30644 from slavapestov/fix-member-type-of-concrete-generic-param-crash
GSB: Fix maybeResolveEquivalenceClass() with member type of concrete type
2020-03-25 22:25:07 -04:00
Anthony Latsis
403004b4c7 [ASTPrinter] Account for contextual where clauses when printing requirements 2020-03-26 04:48:39 +03:00
Pavel Yaskevich
95be170e46 [CSApply] Support dynamic member lookup as component of key path dynamic member lookup
Previously solution application only supported references to
key path dynamic member lookup as components but it should support both kinds.

Resolves: rdar://problem/60225883
Resolves: [SR-12313](https://bugs.swift.org/browse/SR-12313)
2020-03-25 15:21:52 -07:00
David Ungar
db141af397 Merge pull request #30639 from davidungar/rdar-60840456-custom-attr-on-extension
Start lookup *outside* of D when D is, e.g. an ExtensionDecl
2020-03-25 15:12:48 -07:00
Nathan Hawes
a785fa6cee [Frontend][Index] Add frontend option to skip indexing the stdlib (for test performance)
Several tests related to indexing system modules were taking a considerable
amount of time (100+ seconds in the worst case) indexing the standard library.
This adds a frontend option to skip it and updates those tests to pass it.
2020-03-25 14:36:23 -07:00
Slava Pestov
53ab30044c GSB: Fix maybeResolveEquivalenceClass() with member type of concrete type
Fixes <rdar://problem/55401811>, <https://bugs.swift.org/browse/SR-11475>.
2020-03-25 16:53:57 -04:00
David Ungar
de4ff37920 Move RUN line to top of file 2020-03-25 13:07:00 -07:00
Pavel Yaskevich
b73b7c20c4 Merge pull request #30592 from xedin/fallback-diag-for-holes
[ConstraintSystem] Avoid applying invalid solution with fixes
2020-03-25 11:54:08 -07:00
Arnold Schwaighofer
440acea981 Merge pull request #30633 from aschwaighofer/arm64e_does_not_backdeploy
arm64e does not back-deploy
2020-03-25 11:44:48 -07:00
David Ungar
e3ea72127a Add a test case. 2020-03-25 11:34:46 -07:00
Dan Zheng
76ad4abd0a [AutoDiff upstream] Fill in derivative witness table/vtable thunks. (#30634)
Generate `differentiable_function` and `differentiable_function_extract` in
derivative witness table/vtable thunks.

`differentiation_function` is later canonicalized by the differentiation
transform.

Add SIL FileCheck tests.
2020-03-25 11:15:58 -07:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
Nathan Hawes
8b03b05f1d [Index] Add index support for cross import overlays.
Resolves rdar://problem/59445445
2020-03-25 10:04:41 -07:00
Pavel Yaskevich
5f328ad003 [ConstraintSystem] Don't increase SK_Fix score when looking through holes
`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
2020-03-25 09:34:00 -07:00
Arnold Schwaighofer
a6c6ddccf1 arm64e does not back-deploy
rdar://60438869
2020-03-25 09:02:14 -07:00
Dan Zheng
07596cbc9b [AutoDiff upstream] Relax @differentiable for protocol witnesses. (#30629)
Previously, all witnesses of a `@differentiable` protocol requirement were
required to have the same attribute (or one with superset parameter indices).

However, this leads to many annotations on witnesses and is not ideal for
usability. `@differentiable` attributes are really only significant on
public witnesses, so that they are clearly `@differentiable` at a glance (in
source code, interface files, and API documentation), without looking through
protocol conformance hierarchies.

Now, only *public* witnesses of `@differentiable` protocol requirements are
required to have the same attribute (or one with superset parameter indices).
For less-visible witnesses, an implicit `@differentiable` attribute is created
with the same configuration as the requirement's.

Resolves TF-1117.
Upstreams #29771 from tensorflow branch.
2020-03-25 08:13:27 -07:00
marcrasi
025cb9a501 autodiff builtins (#30624)
Define type signatures and SILGen for the following builtins:

```
/// Applies the {jvp|vjp} of `f` to `arg1`, ..., `argN`.
func applyDerivative_arityN_{jvp|vjp}(f, arg1, ..., argN) -> jvp/vjp return type

/// Applies the transpose of `f` to `arg`.
func applyTranspose_arityN(f, arg) -> transpose return type

/// Makes a differentiable function from the given `original`, `jvp`, and
/// `vjp` functions.
func differentiableFunction_arityN(original, jvp, vjp)

/// Makes a linear function from the given `original` and `transpose` functions.
func linearFunction_arityN(original, transpose)
```

Add SILGen FileCheck tests for all builtins.
2020-03-25 02:36:42 -07:00
Pavel Yaskevich
972de2e657 Merge pull request #30627 from LucianoPAlmeida/SR-12382-improve-pointer-conversion-mismatch-diag
[SR-12382] Improve optional pointer conversion mismatch diagnostics
2020-03-25 02:22:59 -07:00
Luciano Almeida
822b424487 [tests] Adding SR-12382 test cases 2020-03-25 02:06:43 -03:00
Rintaro Ishizaki
3841250898 Merge pull request #30515 from rintaro/sourcekit-modulevalidation-rdar59567281
[SourceKit] Save clang module validation time
2020-03-24 17:23:01 -07:00
Mishal Shah
88b093e9d7 Merge pull request #30615 from apple/post-back-master-xcode-11.4
Update master to build with Xcode 11.4
2020-03-24 17:19:37 -07:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
da2023c9a0 [ConstraintSystem] Score solutions based on number of holes
Introduce `SK_Hole` which is used to count a number of "holes" in
a given solution. It is used to distinguish solutions with fewer holes.

Also it makes it possible to check whether a solution has holes but
no fixes, which is an issue and such solution shouldn't be applied
to AST.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
f14e9a8901 Merge pull request #30621 from xedin/extend-nil-diags
[ConstraintSystem] Diagnose more cases of invalid `nil` use during co…
2020-03-24 16:48:29 -07:00
Saleem Abdulrasool
e76fd0c349 Merge pull request #30608 from gribozavr/fix-windows
Use more precise terms in a test
2020-03-24 15:40:32 -07:00
Saleem Abdulrasool
0d56b373be Merge pull request #30599 from 3405691582/OpenBSD_Port_Testing
[test] Setup testing for OpenBSD.
2020-03-24 15:39:49 -07:00
Nathan Hawes
b7bc7bca4e Merge pull request #30551 from nathawes/cross-import-doc-info
[SourceKit/DocSupport] Update cross-import overlay symbols reported in the module doc-info request with their required bystanders.
2020-03-24 15:33:32 -07:00
Rintaro Ishizaki
d0d17114b7 [SourceKit] Disable Windows testing for build_session test cases 2020-03-24 15:29:16 -07:00
Pavel Yaskevich
465b0e193a [ConstraintSystem] Diagnose more cases of invalid nil use during constraint generation
Move check for `nil` destination of conditional casts to `visitNilLiteral` and
add support for `nil?` which wasn't previously detected.
2020-03-24 14:57:27 -07:00
swift-ci
bf4a80bea5 Merge pull request #30617 from aschwaighofer/disable_autodiff_test_arm64e 2020-03-24 14:02:12 -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
Rintaro Ishizaki
22f048e637 [SourceKit] Save clang module validation time
Pass '-fbuild-session-timestamp' and '-fmodules-validate-once-per-build-sessio'
to ClangImporter so that module validation happens only once for the
SourceKit lifetime.

rdar://problem/59567281
2020-03-24 13:38:57 -07:00
Arnold Schwaighofer
f0cdd76f18 Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list
IRGen: Also unique selectors in extended method types list
2020-03-24 12:42:59 -07:00
Arnold Schwaighofer
b50b978dde This test needs adjustment for arm64e
rdar://60834321
2020-03-24 12:15:08 -07:00