Commit Graph

3309 Commits

Author SHA1 Message Date
Slava Pestov
a92724b09c AST: Fix computeSelfParam() to respect __consuming on class methods
Fixes <rdar://problem/58887618>.
2020-01-31 16:37:04 -08:00
swift-ci
84880bcbdc Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-31 11:03:07 -08:00
Arnold Schwaighofer
fce335bf36 SILGen: Fix withoutActuallyEscaping of 'c' closures
They don't have a context and therefore are not consumed.

Fixes a failing assert.

rdar://59046275
2020-01-31 08:57:45 -08:00
swift-ci
e6e06c8752 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-29 09:23:16 -08:00
Adrian Prantl
37e403db78 Compile libraries in testcases with -parse-as-library (NFC)
This is in preparation to a change in serialization of global variables where
this detail will matter.
2020-01-28 17:37:52 -08:00
swift-ci
8bfd9fdbea Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-28 12:43:20 -08:00
Arnold Schwaighofer
18babf7574 SILGen: Lower the type of the return value merge phi in the context of the current function
rdar://58929484
2020-01-28 08:06:02 -08:00
swift-ci
72229ba355 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-24 16:43:36 -08:00
Slava Pestov
305620b354 ClangImporter: Reconcile Clang declaration hidden-ness between loadAllMembers() and lazy loading
Lazy loading checked if the ClangDecl was hidden, but loading all
members did not. Let's make loadAllMembers() behave like the lazy
path, and fix some of the mock SDKs in the test suite.
2020-01-24 17:07:08 -05:00
Slava Pestov
caf1f1f6b7 SILGen: Uncomment a FIXME in a test since it works now 2020-01-24 17:06:48 -05:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
Arnold Schwaighofer
8ed908f923 Revert "[silgen] When SILGenLValue accesses ref_elt_addr, emit unsafe access for immutable or non accessing uses instead of not emitting any begin_access."
This reverts commit a3b68e6df5.

Speculative revert because I believe it is the cause of the failures on
the swift-master-source-compat-suite-enable-verify-exclusivity bot.

rdar://58529726
2020-01-15 10:12:23 -08:00
Slava Pestov
47df8a1257 SILGen: Fix assert when bridging no-payload enum case to Any
It's possible for a value of a non-trivial type to have no cleanup,
if the value was constructed from a no-payload enum case. Tweak
the assert to check the value's ownership instead of checking the
type.

Fixes <https://bugs.swift.org/browse/SR-12000>, <rdar://problem/58455443>.
2020-01-14 15:31:02 -05:00
swift-ci
9c48cfe400 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 12:04:20 -08:00
Brent Royal-Gordon
c896794946 Merge pull request #29135 from brentdax/concise-for-thee-but-not-for-me
Use #file string for force-unwrap and force-try
2020-01-13 11:52:24 -08:00
swift-ci
e6fe0bc1e3 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 05:23:28 -08:00
Slava Pestov
0e801c60fc SILGen: Fix crash when a closure captures two values with dynamic 'Self' type
We give special treatment to a capture of a value with dynamic 'Self'
type, by adding it at the end of the capture list. This ensures that
IRGen can recover the 'Self' metadata from this parameter if needed.

However, the code would crash with an assertion if there were multiple
captured values having the dynamic 'Self' type. This was slightly more
difficult to spell before SE-0068, but it was still possible if you
tried; now its completely trivial.

Fixes <https://bugs.swift.org/browse/SR-11928>, <rdar://problem/57823886>.
2020-01-10 23:15:53 -05:00
swift-ci
52c5ecd291 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 16:23:41 -08:00
Brent Royal-Gordon
0f476284d1 Use #file string for force-unwrap and force-try
This ensures that -enable-experimental-concise-pound-file affects more of the file names that might be automatically embedded in a binary.
2020-01-10 13:48:45 -08:00
Arnold Schwaighofer
0c99cd9734 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 08:00:41 -08:00
Michael Gottesman
a3b68e6df5 [silgen] When SILGenLValue accesses ref_elt_addr, emit unsafe access for immutable or non accessing uses instead of not emitting any begin_access. 2020-01-09 15:22:09 -08:00
Slava Pestov
377d22e757 SILGen: Use the correct generic environment in vtable thunks
Make sure we use the generic environment derived from the
generic signature of the vtable thunk itself, which can now
be different than the generic signature of the derived
method.

This allows vtable thunks that re-abstract generic requirements
to lower all the way through to IRGen.
2020-01-08 22:19:15 -05:00
Slava Pestov
652f8ee95b SIL: VTable thunks should use the 'override generic signature'
We recently added some checking to ensure that a method override's
generic signature does not have any generic requirements not
satisfied by the base method.

Loosening requirements in the other direction was allowed, because
it means the derived method can be called on potentially more types
than the base method.

However, if the generic signatures don't match, a thunk must be
emitted. While we correctly determined whether a thunk should be
emitted, the thunk had the wrong generic signature, and therefore
the wrong calling convention, which would cause crashes at runtime.

Fixes <rdar://problem/57429775>.
2020-01-08 22:19:15 -05:00
Michael Gottesman
9b9760eb4c [silgen] Change silgen destructor to access ref_element_addr through begin_access [deinit]. 2020-01-08 12:49:05 -08:00
swift_jenkins
e90b4ab8be Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 19:39:07 -08:00
Slava Pestov
1ee4403fb7 Merge pull request #28985 from slavapestov/property-wrapper-modify-transparent
Sema: Don't mark property wrapper 'modify' accessors transparent
2020-01-02 22:25:06 -05:00
swift_jenkins
cd9d23d5c4 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 17:19:15 -08:00
Doug Gregor
79776436d8 Merge pull request #28984 from DougGregor/de-de-virtualize-for-each
[Type checker] Stop devirtualizing the reference to IteratorProtocol.next()
2020-01-02 17:08:59 -08:00
swift_jenkins
add386ded3 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 15:59:15 -08:00
Doug Gregor
716c72cadb Merge pull request #28380 from DougGregor/for-each-in-constraint-solver
[Type checker] Fold more for-each type checking into the constraint solver
2020-01-02 15:43:46 -08:00
Slava Pestov
1337925608 Sema: Don't mark property wrapper 'modify' accessors transparent
There are certain conditions that cause them to reference
non-public properties, in particular if the property
wrapper is implemented via a subscript taking a keypath.

Instead of trying to detect this specific case though (and
possibly missing others), I'm just going to decree that
'modify' is never going to be transparent for property
wrappers.

Fixes <rdar://problem/57609867>.
2020-01-02 18:30:37 -05:00
Doug Gregor
97b5a0d5fb [Type checker] Stop devirtualizing the reference to IteratorProtocol.next().
Rather than having the type checker look for the specific witness to
next() when type checking the for-each loop, which had the effect of
devirtualizing next() even when it shouldn't be, leave the formation
of the next() reference to SILGen. There, form it as a witness
reference, so that the SIL optimizer can choose whether to
devirtualization (or not).
2020-01-02 14:39:00 -08:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
swift_jenkins
ffaec0727d Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 09:59:09 -08:00
Michael Gottesman
f4dfbe94e5 [ownership] Require all operands of ref_tail_addr to have guaranteed ownership.
This ensures that the optimizer has a summary of where the ref_tail_addr will no
longer be used. This is important when analyzing the lifetime of the base of the
ref_tail_addr.

I also cleaned up a little the description around the specification for this in
OperandOwnership. Now all instructions that are "INTERIOR_POINTER_PROJECTIONS"
have their own section/macro as a form of self documenting.
2019-12-31 19:50:16 -08:00
swift_jenkins
511931489c Merge remote-tracking branch 'origin/master' into master-next 2019-12-20 07:19:11 -08:00
Slava Pestov
e4626263c3 AST: More consistent definition of a 'local capture'
This commit adds a new ValueDecl::isLocalCapture() predicate and
uses it in the right places. The predicate is true if the
declaration is in local context, *or* if its at the top level of
the main source file and follows a 'guard' statement.

Fixes <rdar://problem/23051362> / <https://bugs.swift.org/browse/SR-3528>.
2019-12-19 23:47:24 -05:00
Slava Pestov
04bf432774 SILGen: Diagnose invalid captures of top-level bindings
A method of a nominal type is not allowed to capture anything.
If we did compute a capture list, clear it out to preserve
downstream invariants.

This can happen because not all invalid captures involving
nominal types in local context can be diagnosed in Sema.

In particular, we allow a method of a local type to
reference a local function from an outer scope, as long as
that local function does not have any (transitive) captures.
Since Sema cannot validate the latter condition, it punts
and allows any reference to a FuncDecl in local context.

When emitting the captures in this situation, SILGen will
diagnose the problem using the existing 'forward reference'
logic.

The diagnostic is sub-optimal -- it should talk about a
reference from inside a local type, and not a 'forward
reference'. But still better than crashing.
2019-12-19 23:46:01 -05:00
swift_jenkins
fd390dfa5c Merge remote-tracking branch 'origin/master' into master-next 2019-12-14 08:00:41 -08:00
Slava Pestov
594044a049 Sema: Clean up handling of protocol operators with concrete operands
In this case we would "devirtualize" the protocol requirement call
by building the AST to model a direct reference to the witness.

Previously this was done by recursively calling typeCheckExpression(),
but the only thing this did was recover the correct substitutions
for the call.

Instead, we can just build the right SubstitutionMap directly.
Unfortunately, while we serialize enough information in the AST
to devirtualize calls at the SIL level, we do not for AST Exprs.

This is because SIL devirtualization builds a reference to the
witness thunk signature, which is an intermediate step between
the protocol requirement and the witness. I get around this by
deriving the substitutions from walking in parallel over the
interface type of the witness, together with the inferred type
of the call expression.
2019-12-14 01:02:33 -05:00
swift_jenkins
59fa47cc7a Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 15:20:06 -08:00
Slava Pestov
1401cbaf2b SILGen: Fudge emitProlog() to emit unreachable later
For some reason, doing it in the other order causes a crash.
I suspect this is because we create new instructions below,
but if there's no insertion point, the instruction is never
added to a basic block.
2019-12-13 15:39:47 -05:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Saleem Abdulrasool
e3bed008c7 test: loosen the #file, #filePath tests for Windows
Be more lenient about the path separator.  This repairs the tests on
Windows after #25656.
2019-12-08 20:35:08 -08:00
Brent Royal-Gordon
e1e7a3fe75 Merge pull request #25656 from brentdax/file-name-basis
Shorten #file and add #filePath (behind an experimental flag)
2019-12-06 21:34:58 -08:00
Hamish Knight
0c1330dd9e [CS] Resolve callees for callAsFunction .member exprs (#28604)
[CS] Resolve callees for callAsFunction `.member` exprs
2019-12-06 13:34:23 -08:00
Doug Gregor
d23ab39a6f Merge pull request #28589 from DougGregor/wrapper-type-default-init-crash
[Property wrappers] Fix crash due to wrapped type/wrapper type confusion
2019-12-06 11:30:33 -08:00
Hamish Knight
8a83440ce1 [CS] Resolve callees for callAsFunction ".member" exprs
Apply the same checks as ApplyExprs to
UnresolvedMemberExprs in getCalleeLocator to
resolve callees in cases where they're used with
`callAsFunction` in addition to a weird edge case
where we currently allow them with constructor
calls, e.g:

```
struct S {
  static let s = S.self
}

let x: S = .s()
```

Arguably we should be representing ".member()"
expressions with an UnresolvedMemberExpr + CallExpr,
which would avoid the need to apply these special
cases, and reject the above syntax for not using
an explicit ".init". Doing so will likely require
a bit of hacking in CSGen though.

Resolves SR-11909.
2019-12-06 11:21:37 -08:00
Arnold Schwaighofer
b6e6ace01e Property wrapper backing initializers are not dynamically replaceable 2019-12-05 10:48:54 -08:00
Doug Gregor
493bed0043 [Property wrappers] Fix crash due to wrapped type/wrapper type confusion.
We had two predicates that were used to determine whether the default
argument for a wrapped property in the memberwise initializer would be
of the wrapper type (e.g., Lazy<Int>) vs. the wrapped type
(Int). Those two predicates could disagree, causing a SILGen assertion
and crash. Collapse the two predicates into one correct one,
fixing rdar://problem/57545381.
2019-12-05 09:27:30 -08:00