Commit Graph

58361 Commits

Author SHA1 Message Date
Dan Zheng
146c11ec80 [AutoDiff upstream] Add differentiable_function canonicalization. (#30818)
Canonicalizes `differentiable_function` instructions by filling in missing
derivative function operands.

Derivative function emission rules, based on the original function value:

- `function_ref`: look up differentiability witness with the exact or a minimal
  superset derivative configuration. Emit a `differentiability_witness_function`
  for the derivative function.
- `witness_method`: emit a `witness_method` with the minimal superset derivative
  configuration for the derivative function.
- `class_method`: emit a `class_method` with the minimal superset derivative
  configuration for the derivative function.

If an *actual* emitted derivative function has a superset derivative
configuration versus the *desired* derivative configuration, create a "subset
parameters thunk" to thunk the actual derivative to the desired type.

For `differentiable_function` instructions formed from curry thunk applications:
clone the curry thunk (with type `(Self) -> (T, ...) -> U`) and create a new
version with type `(Self) -> @differentiable (T, ...) -> U`.

Progress towards TF-1211.
2020-04-05 20:19:10 -07:00
Brent Royal-Gordon
121fa9a058 Ignore transitive ObjC imports when cross-importing
This behavior change reduces the chance of unexpected and unwanted cross-imports being performed.

Fixes rdar://problem/60554019.
2020-04-05 19:06:59 -07:00
Holly Borla
5f00a1b077 [SILGen] In a memberwise initializer, apply the property wrapper backing
initializer for property wrappers that are not memberwise initialized but
have an explicit original wrapped value.
2020-04-05 19:02:37 -07:00
Holly Borla
bbfcb55e9e [Property Wrappers] Inject the opaque value placeholder for a property
wrapper original wrapped value expression inside of CSApply.

This prevents type checking the synthesized backing storage initializer
twice - once with the original expression and again with the placeholder.
2020-04-05 19:02:37 -07:00
Ivan Smetanin
0beddca9e9 Unify diagnose invalid attr producing 2020-04-05 19:31:51 +03:00
swift-ci
51a2a07be6 Merge pull request #30758 from nathawes/cross-import-fixes 2020-04-04 15:38:27 -07:00
Joe Groff
14ef485548 Merge pull request #30799 from jckarter/keypath-import-as-member
SILGen: Use the original function address as the ID for key paths to import-as-member properties.
2020-04-04 12:54:08 -07:00
Ivan Smetanin
f9b1a524da Fix escaping_optional_type_argument producing behavior 2020-04-04 20:22:04 +03:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -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
Pavel Yaskevich
5eea0ae0fc Merge pull request #30803 from xedin/rdar-60961087
[CSGen] Bring back performance hack for named patterns with an initializer expression
2020-04-03 22:16:16 -07:00
Doug Gregor
bdb2aeecfd Merge pull request #30788 from DougGregor/driver-darwin-sdk-version-to-linker
[Driver] Use -platform_version to specify platform versions for the Darwin linker
2020-04-03 20:56:40 -07:00
Cyndy Ishida
6a29923c5e [TBDGen] update tbd version
Short overview of new TBD-v4 format changes:

* special section for reexported symbols (which is not seen any
differently to the linker)

* target based slices as opposed to just architecture

more information in: rdar://problem/60586390
2020-04-03 20:38:15 -07:00
Slava Pestov
5f51546480 Sema: Fix source range for curry thunks
Fixes <rdar://problem/61117301> / <https://bugs.swift.org/browse/SR-12496>.
2020-04-03 23:26:04 -04:00
Slava Pestov
e5a7fd3114 Merge pull request #30802 from slavapestov/var-decl-usage-checker-fixes
VarDeclUsageChecker fixes
2020-04-03 23:25:19 -04:00
nate-chandler
9c1a70358c Merge pull request #30796 from nate-chandler/generic-metadata-prespecialization-components/require-same-file
[prespecialized metadata] Require same file without wmo.
2020-04-03 18:31:09 -07:00
Nathan Hawes
1a65b84a42 [IDE] Completion after a qualifying module should return symbols from its shadowing cross-import overlays. 2020-04-03 16:04:32 -07:00
Nathan Hawes
9f6f76308e Add method to ModuleDecl to lazily compute the underlying module for cross-import overlays
Also update code completion, indexing, interface generation and doc info to use it.
2020-04-03 16:04:32 -07:00
Pavel Yaskevich
5c58bb8432 [CSGen] Bring back performance hack for named patterns with an initializer expression
Unfortunately we still need this performance hack because otherwise
e.g. if initializer returns a tuple its type is going to be connected
to a type variable representing a pattern type, which means all of the
tuple element types are going to form a single constraint system component.

Resolves: rdar://problem/60961087
2020-04-03 15:56:27 -07:00
Pavel Yaskevich
80ac793ecd [CSGen] Adjust locators for some patterns
In each of the following situations `getTypeForPattern` would
add a new pattern element to the path:

- Element of a tuple pattern
- Sub-pattern of a typed pattern
- Sub-pattern of optional .some
2020-04-03 15:56:27 -07:00
Nate Chandler
6c178c7c62 [prespecialized metadata] Require same file without wmo.
Without whole module optimization, the metadata accessors are emitted on
a per-file basis.  The result is that if the file containing a generic
type is processed before the file containing a usage of that type that
would result in that prespecialization, the metadata accessor would have
already been emitted by the time that the usage is noted, making it
impossible for the newly created prespecialization to be returned from
the already-emitted metadata accessor.

Here, require that either whole module optimization is enabled so that
the metadata accessors are all emitted at once at the end, or else that
the usage of the prespecialization is in the same file as the type is
declared.
2020-04-03 15:37:36 -07:00
Hamish Knight
109ec5dd08 Merge pull request #30792 from hamishknight/storage-access-codes
[Sema] Fix a couple of property override crashers
2020-04-03 15:27:07 -07:00
Slava Pestov
319a026a9a Sema: Always compute captures when we type check a function body 2020-04-03 18:14:36 -04:00
Holly Borla
c301176ca6 [ConstraintSystem] Allow SolutionApplicationTarget to store the
innermost call to init(wrappedValue:) if the target is for initialization
of a property wrapper's backing storage.
2020-04-03 15:12:12 -07:00
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Robert Widmann
f13c76cf51 Add ModuleDecl Base Case To extractNearestSourceLoc
ModuleDecl is its own declaration context.
2020-04-03 14:52:21 -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
Slava Pestov
93f0faf109 Sema: Fix false-positive var => let warning in VarUsageDeclChecker
Fixes <rdar://problem/60563962>.
2020-04-03 17:27:43 -04:00
Joe Groff
e5b0ffc2df SILGen: Use the original function address as the ID for key paths to import-as-member properties.
If an import-as-member property was used in a key path, we'd try to identify the component by its
foreign-to-native thunk, which isn't normally generated (causing a crash from the missing symbol)
and wouldn't be globally unique even if it were. Fixes rdar://problem/60519829.
2020-04-03 14:08:24 -07:00
Doug Gregor
82ceb29576 [Driver] Fix platform name to match what the linker does, not what it says 2020-04-03 13:51:29 -07:00
Holly Borla
d22b984a93 [Expr] Allow OpaqueValueExpr to store an underlying expression 2020-04-03 13:47:56 -07:00
Hamish Knight
6a7b2e0040 [Sema] Handle metatypes in buildSelfReference
Before attempting to get the superclass of a
self parameter type, check to see if we have a
metatype, and perform the necessary unwrapping and
re-wrapping if needed.
2020-04-03 09:18:58 -07:00
Hamish Knight
c926da1b07 [Sema] Adjust property wrapper mutability application
Only apply the relevant property wrapper mutability
when we're performing an access via the wrapped
value.
2020-04-03 08:26:36 -07:00
Andrew Trick
1c12de3241 Fix LICM combined load/store hoisting/sinking optimization.
This loop optimization hoists and sinks a group of loads and stores to
the same address.

Consider this SIL...

PRELOOP:
  %stackAddr = alloc_stack $Index
  %outerAddr1 = struct_element_addr %stackAddr : $*Index, #Index.value
  %innerAddr1 = struct_element_addr %outerAddr1 : $*Int, #Int._value

  %outerAddr2 = struct_element_addr %stackAddr : $*Index, #Index.value
  %innerAddr2 = struct_element_addr %outerAddr2 : $*Int, #Int._value

LOOP:
  %_ = load %innerAddr2 : $*Builtin.Int64
  store %_ to %outerAddr2 : $*Int
  %_ = load %innerAddr1 : $*Builtin.Int64

There are two bugs:

1) LICM miscompiles code during combined load/store hoisting and sinking.

When the loop contains an aliasing load from a difference projection
value, the optimization sinks the store but never replaces the
load. At runtime, the load reads a stale value.

FIX: isOnlyLoadedAndStored needs to check for other load instructions
before hoisting/sinking a seemingly unrelated set of
loads/stores. Checking side effect instructions is insufficient. The
same bug could happen with stores, which also do not produce side
effects.

Fixes <rdar://61246061> LICM miscompile:
Combined load/store hoisting/sinking with aliases

2) The LICM algorithm is not robust with respect to address projection
   because it identifies a projected address by its SILValue. This
   should never be done! It is trivial to represent a project path
   using an IndexTrieNode (there is also an abstraction called
   "ProjectionPath", but it should _never_ actually be stored by an
   analysis because of the time and space complexity of doing so).

The second bug is not necessary to fix for correctness, so will be
fixed in a follow-up commit.
2020-04-03 08:25:20 -07:00
Andrew Trick
73ee38c162 Add tracing to LICM for reloaded store/restored load optimization. 2020-04-03 08:25:20 -07:00
swift-ci
5f17f5b17d Merge pull request #30790 from MForster/import-const-members 2020-04-03 07:58:54 -07:00
Michael Forster
98bbb81f82 [C++] Make const member variables read-only
This imports const members of C++ structs/classes stored properties with
an inaccessible setter.

Note that in C++ there are ways to change the values of const members,
so we don't use `WriteImplKind::Immutable` storage.

Resolves: [SR-12463](https://bugs.swift.org/browse/SR-12463)
2020-04-03 13:15:33 +02:00
Erik Eckstein
5a5cbf78a0 EscapeAnalysis: fix a problem with unchecked_addr_cast
In case an unchecked_addr_cast is used to convert between pointer and non-pointer, we missed some escaping values.
This can be the case when using C unions.

https://bugs.swift.org/browse/SR-12427
rdar://problem/60983997
2020-04-03 09:07:34 +02:00
eeckstein
59368a6e27 Merge pull request #30766 from eeckstein/fix-keypath-opt
SILOptimizer: fix a crash in the keypath optimization
2020-04-03 08:45:35 +02:00
Andrew Trick
64348904e9 Merge pull request #30786 from atrick/fix-access-api
Fix the getAddressAccess API.
2020-04-02 21:21:51 -07:00
Doug Gregor
970ff6b818 [Driver] Read SDK version information to pass to the Darwin linker.
Recent-ish SDKs for Darwin platforms include an SDKSettings.json
file with version information and Catalyst SDK version mappings. Read
these (when available) and use them to pass the appropriate SDK
version down to the Darwin linker via `-platform_version`.

Finishes rdar://problem/55972144.
2020-04-02 21:07:26 -07:00
Doug Gregor
6edc32568c [Driver] Adjust Mac Catalyst deployment target to >= iOS 13 for the linker
Mac Catalyst was introduced with an iOS deployment target of 13.0.
If given a deployment target before that, adjust the deployment target
to 13.0 for the linker.
2020-04-02 21:07:26 -07:00
Doug Gregor
336c0c2d54 [Driver] Use -platform_version to specify platform versions for the Darwin linker
Standardize the way in which we pass platform version information to
the Darwin linker, using the `-platform_version` option. In the case
of Mac Catalyst, there may be two such platform arguments.

The eventual point of this refactoring is to also pass information
about the SDK version, which `-platform_version` supports but the
mix of `-*_version_min` parameters do not. For now, the SDK
version is stubbed out to 0.0.0, which is this option's "unknown"
value.

Part of rdar://problem/55972144.
2020-04-02 21:07:26 -07:00
Dan Zheng
e2014e3366 Merge pull request #30781 from dan-zheng/differentiation-transform-skeleton 2020-04-02 21:01:53 -07:00
Artem Chikin
b679fd8738 Add -Rcross-import option
It is an optional, user-accessible mechanism to have the compiler tell you what it’s cross-importing.

Resolves rdar://problem/60381893
2020-04-02 19:45:39 -07:00
Andrew Trick
ec1545fac2 Fix the getAddressAccess API.
The API was accidentally undefined, presumably because I checked in
the wrong code or there was a bad merge. The API will be used by
upcoming commits.

Meanwhile, getAccessedAddress was not stripping access markers, which
means some analysis may have been too conservative.

This fix could expose issues by making existing analyses more effective.
2020-04-02 18:49:46 -07:00
Dan Zheng
4671dc5c0f [AutoDiff upstream] Add TBDGen for AutoDiff symbols.
Emit symbols for `@differentiable` and `@derivative` declaration attributes:
- Differentiability witness symbols.
- Derivative function (JVP/VJP) symbols.
- Linear map (differential/pullback) symbols.

Add TBDGen test.
2020-04-03 01:14:28 +00:00
Joe Groff
a87369b53c Merge pull request #30763 from jckarter/protocol-infer-objc-error-convention
Sema: Infer error convention from @objc protocol requirements.
2020-04-02 16:04:37 -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
Dan Zheng
aa66cce808 [AutoDiff upstream] Add differentiation transform.
The differentiation transform does the following:
- Canonicalizes differentiability witnesses by filling in missing derivative
  function entries.
- Canonicalizes `differentiable_function` instructions by filling in missing
  derivative function operands.
- If necessary, performs automatic differentiation: generating derivative
  functions for original functions.
  - When encountering non-differentiability code, produces a diagnostic and
    errors out.

Partially resolves TF-1211: add the main canonicalization loop.

To incrementally stage changes, derivative functions are currently created
with empty bodies that fatal error with a nice message.

Derivative emitters will be upstreamed separately.
2020-04-02 15:43:57 -07:00