Commit Graph

39091 Commits

Author SHA1 Message Date
Xi Ge
aa39afa32a test: disable Runtime/superclass_constraint_metadata_resilient_superclass_future.swift
rdar://61345988
2020-04-06 09:48:49 -07:00
Arnold Schwaighofer
f887422a6c Opaque type substitution also needs to take the access of a opaque type decl into account.
Otherwise, we can access an opaque type descriptor that is private to a
translation unit.

rdar://60123853
2020-04-06 09:16:28 -07:00
Dan Zheng
426583523e Merge pull request #30826 from dan-zheng/SR-12526
[AutoDiff] Add SR-12526 negative test.
2020-04-06 04:55:54 -07:00
swift-ci
5b39fa7aed Merge pull request #30823 from MForster/test-layout 2020-04-06 02:46:30 -07:00
Dan Zheng
52b771dfe4 [AutoDiff] Add SR-12526 negative test.
Add negative test for SR-12526: `@derivative` attribute cross-module
deserialization crash.
2020-04-06 02:36:18 -07:00
Dan Zheng
0c1d4b5adf [AutoDiff] Enable cross-file derivative registration.
Lift temporary cross-file derivative registration restriction.

`@derivative` attribute type-checking simplications coming soon: TF-1099.
Original function and derivative function must have same access level, with one
exception: public original functions may have internal `@usableFromInline`
derivatives.
2020-04-06 02:36:02 -07:00
Michael Forster
f609a7cbb4 Unify layout for C++ interop tests
This was discussed here:
https://forums.swift.org/t/reorganize-swift-compiler-tests-for-c-objc-c-interop/34411

Resolves: [SR-12475](https://bugs.swift.org/browse/SR-12475)
2020-04-06 09:38:18 +02:00
Dan Zheng
52374bfcca Add TF-1232 negative test: proper mangling for AutoDiff-generated declarations.
IRGenDebugInfo crash due to lack of proper mangling for AutoDiff-generated
declarations: linear map structs and branching trace enums.
2020-04-05 21:39:38 -07:00
Dan Zheng
d6bbf97886 Add simple generated derivative code FileCheck test. 2020-04-05 21:15:23 -07:00
Dan Zheng
b833271215 Simplify test before stdlib derivatives are upstreamed. 2020-04-05 20:35:35 -07:00
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
marcrasi
15f512b81b [AutoDiff] fix SR-12493 (#30817)
We simply needed to upstream `TypeSubstCloner::visitDifferentiableFunctionExtractInst`.
The code has a detailed comment explaining what it does.
2020-04-05 19:36: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
c130848d62 [Test] Add a regression test for property wrapper backing initializers that
involve inout closure parameters and were previously type checked twice.
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
Konrad `ktoso` Malawski
5faf82c553 Improve usability of _mangledTypeName with Any.Type arguments 2020-04-05 12:27:50 +09: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
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
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
Robert Widmann
bce1dd6b49 Remove test that is incompatible with laziness
Going through sil-opt is going to print the contents of the module
without forcing the attribute which renders the test toothless. Now that
we have the multifile test, we're testing it can be round-tripped
through serialization anyhow.
2020-04-03 18:26:54 -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
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
nate-chandler
feba039217 Merge pull request #30785 from nate-chandler/rdar60790020
[Runtime] Handle incomplete class metadata in _checkGenericRequirements.
2020-04-03 15:32:53 -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
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
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
Nate Chandler
2863f1964d [Runtime] Handle incomplete class metadata in _checkGenericRequirements.
When constructing the metadata for a type Gen<T : Super>
where Super is a superclass constraint, the generic argument K at which
the metadata for Gen is being instantiated is verified to be a subclass
of Super via _checkGenericRequirements.

Previously, that check was done using swift_dynamicCastMetatype.  That
worked for the most part but provided an incorrect answer if the
metadata for K was not yet complete.  These classes are incomplete more
often thanks to __swift_instantiateConcreteTypeFromMangledNameAbstract.

That issue occurred concretely in the following case:

  Framework with Library Evolution enabled:

    open class Super { ... }
    public struct Gen<T : Super> {
    }

  Target in a different resilience domain from that framework:

    class Sub : Super {
      var gen: Gen<Sub>?
    }

Here, the mechanism for checking whether the generic argument K at which
the metadata for Gen is being instantiated handles the case where K's
metadata is incomplete.  At worst, every superclass name from super(K)
up to Super are demangled to instantiate metadata.  A number of faster
paths are included as well.

rdar://problem/60790020
2020-04-03 13:28:54 -07:00
Ewa Matejska
36cf56651f fixing up some tests and turning off SIMD extension which uses @_alwaysEmitIntoClient since that's not supported yet. 2020-04-03 12:59:47 -07:00
Michael Ilseman
5815468ebb Merge pull request #30719 from milseman/tilde_equality
[String] Concrete String/Substring overloads for ~=
2020-04-03 11:12:32 -07:00
Ewa Matejska
b72aca9a5c Merge branch 'master' of https://github.com/apple/swift 2020-04-03 10:40:56 -07:00
3405691582
f8d0174b85 Build system recognizes OpenBSD.
Commit for CMake and build scripts to recognize OpenBSD. To keep this
commit relatively short, this just deals with the rather simple and
uncontroversial changes to the build system.

Note that OpenBSD calls "x86_64" as "amd64", Since the Swift stdlib will
be put in a subdirectory named after ARCH, to ensure the standard
library is properly found later, we use the native architecture name for
OpenBSD in the build system rather than trying to deal with the
difference the other way around.
2020-04-03 13:34:17 -04: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
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
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