Commit Graph

1287 Commits

Author SHA1 Message Date
David Zarzycki
6d52f434af [AST] NFC: Create abstract class for MemberRefExpr/SubscriptExpr
This consolidation includes two examples of where this useful. There are
probably more.
2018-05-19 12:33:35 -04:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00
Joe Groff
fce4988dd0 SILGen: Emit default arguments as "delayed arguments".
This causes default arguments to get emitted after formal evaluation of `self`, allowing protocol methods to access the opened `Self` type of an existential receiver. Fixes rdar://problem/39524104
2018-05-17 13:17:44 -07:00
Joe Groff
aeb16baa6f Revert "SILGen: Open existential lvalues on entry into an OpenExistentialExpr again."
This reverts commit 742e7fc583. This
causes other source compatibility regressions due to the extended exclusive access to
the existential (such as rdar://problem/39524104). A false-positive
exclusivity failure might lead to runtime errors, whereas the cases we
can't support previous to this patch can at least reliably be handled
statically.
2018-05-17 13:17:44 -07:00
Doug Gregor
467456ea3f [SILGen] Get keypath emission logic off Substitution. 2018-05-11 17:37:27 -07:00
Doug Gregor
cb3bf10d62 [SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply(). 2018-05-11 17:37:27 -07:00
Doug Gregor
5c0733f3ac [SILGen] Eliminate Substitution from key-path equals/hash generation. 2018-05-11 17:37:27 -07:00
Doug Gregor
c9b50e0171 [SILGen] Eliminate SubstitutionList from the LValue infrastructure. 2018-05-11 17:37:27 -07:00
Doug Gregor
0bf0a1ee6a [SILGen] Eliminate more SubstitutionLists for accessor calls. 2018-05-11 17:37:26 -07:00
Doug Gregor
74902897e7 [IRGen] Eliminate SubstitutionList from IRGen. 2018-05-11 17:37:26 -07:00
Doug Gregor
1af6cb9b6e [SILGen] Remove SubstitutionList from most of key-path SIL generation. 2018-05-11 17:37:26 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
swift-ci
63856d4d1c Merge pull request #16414 from rudkx/fix-typo-in-comment 2018-05-05 00:24:19 -07:00
Mark Lacey
07a9b13728 Fix typo in comment. 2018-05-04 12:16:19 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Doug Gregor
791df5ba55 [AST] Cache the computed SubstitutionList for a SubstitutionMap.
Every SubstitutionMap::toList() invocation would ASTContext-allocate
arrays for all of the conformances, then return a SmallVector of the
underlying substitutions, which both wastes memory *and* puts the onus
on the caller to allocate a copy of that outer SmallVector into the
ASTContext if it's going to be stored anywhere.

Stop the madness by caching an ASTContext-allocated SubstitutionList
within the storage for the SubstitutionMap. This both reduces repeated
allocations and eliminates the potential for errors.
2018-05-03 10:38:01 -07:00
Doug Gregor
7e08b66499 [SIL] Use SubstitutionMap in KeyPathInst rather than SubstitutionList. 2018-05-03 08:48:54 -07:00
Doug Gregor
5724338abe [SIL] Switch "external" key path pattern components to SubstitutionMap.
Eliminates another source of SubstitutionList.
2018-05-03 08:48:54 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
a6dfe0ff88 [SIL] Use SubstitutionMap in KeyPathInst rather than SubstitutionList. 2018-05-03 00:05:21 -07:00
Doug Gregor
25b9afe20f [SIL] Switch "external" key path pattern components to SubstitutionMap.
Eliminates another source of SubstitutionList.
2018-05-03 00:05:21 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Arnold Schwaighofer
1f65ee25f6 Distinguish between withoutActuallyEscaping and passing @noescape
Objective C closures when reporting that a closure has escaped

rdar://39682865
2018-05-01 07:24:19 -07:00
Karoy Lorentey
45cb8b7123 [SE-0206][stdlib] De-underscore Hasher 2018-04-24 17:42:42 +01:00
Arnold Schwaighofer
e36655fddc SILGen: Remove PostponedCleanup in favor or the SIL pass that fixes
closure lifetimes.

SILGen will now unconditionally emit

  %cvt = convert_escape_to_noescape [guaranteed] %op

instructions. The mandatory ClosureLifetimeFixup pass ensures that %op's
lifetime spans %cvt's uses.

The code in DefiniteInitialization that handled a subset of cases is
removed.
2018-04-13 13:44:09 -07:00
Arnold Schwaighofer
b510227224 SILGen: Remove variable with negated name: 2018-03-30 08:51:06 -07:00
Arnold Schwaighofer
3ab1580cf9 SILGen: Don't postpone the cleanup of the convertEscapeToNoEscape inside an bind optional
This would violate dominance since the convertEscapeToNoEscape
instruction does not dominate the postpone point.

rdar://38124009
2018-03-30 06:20:13 -07:00
Joe Groff
8346603e97 Merge pull request #15459 from jckarter/keypath-force-index-equatable
Sema: Ensure Equatable conformance is forced for key path indices.
2018-03-23 16:04:57 -07:00
Joe Groff
c6eab5cb2b SILGen: Clean up conformance handling in getOrCreateKeyPathEqualsAndHash.
Replace manual substitution mapping by using the existing ProtocolConformanceRef::getAssociatedConformance helper to look up the Equatable conformance from Hashable. Replace use of manual Substitution construction with SubstitutionMaps.
2018-03-23 12:29:13 -07:00
Arnold Schwaighofer
3fe9472e59 SILGen: Cleanup visitMakeTemporarilyEscapableExpr
NFC intended.
2018-03-21 11:07:13 -07:00
Arnold Schwaighofer
eac5f83861 SILGen: Don't crash on withoutActuallyEscaping of objc blocks
rdar://38689227
2018-03-21 07:58:17 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Joe Groff
2ea3aa9f8e Merge pull request #15314 from jckarter/keypath-class-generic-member
SILGen: Fix issues with class-constrained generics and keypaths.
2018-03-19 12:34:08 -07:00
Joe Groff
b71686c736 SILGen: Fix issues with class-constrained generics and keypaths.
- Fix some type system issues with looking up member types in/out of context.
- Correctly upcast a class-constrained existential or archetype to the base class when referencing a base class field on a generic type.

Fixes SR-7106 | rdar://problem/38070998.
2018-03-17 10:25:17 -07:00
Mark Lacey
85f25003ce Replace uses of getOptionalObjectType(bool &).
Instead, use the one that doesn't have a reference parameter.
2018-03-16 21:19:49 -07:00
Michael Gottesman
dde4f58625 [+0-all-args] Change emitBindOptional to use a switch_enum instead of a select_enum. 2018-03-15 17:28:57 -07:00
Michael Gottesman
aa9b27802a [silgen] Add helper methods to SwitchEnumBuilder for creating .Some, .None cases.
I also used it to clean up a few uses of SwitchEnumBuilder.
2018-03-15 17:28:47 -07:00
Michael Gottesman
6b2ca79381 [silgen] Make NormalCaseHandler and DefaultCaseHandler take SwitchCaseFullExpr as movable rvalues.
This fits more with the notion of the API, that the user is being given a scope
that was already setup for them and that they must decide when to pop.
2018-03-15 17:28:47 -07:00
Joe Groff
a795b4fc0c SIL: Move responsibility for external keypath equals/hash to the caller.
A public subscript might have generic indexes that aren't unconditionally Hashable, or might use indexes that are retroactively made Hashable, so the property descriptor on the implementer's side can't always resiliently provide this information to the final instantiated KeyPath.
2018-03-14 14:05:49 -07:00
Michael Gottesman
abda01ac37 [+0-normal-args] Change flattenOptional to use switch_enum instead of select_enum+cond_br.
Along the .none path, select_enum+cond_br causes the ownership verifier to
trigger since the .none path looks like a leak. By using a switch_enum, we avoid
this problem since the ownership verifier thinks the switch_enum consumes the
input value and views the owned value along the .some path as a value with
separate ownership.

rdar://34222540
2018-03-11 12:22:34 -07:00
Michael Gottesman
f6ec0f09bf Merge pull request #15118 from gottesmm/pr-cbca07b2b7cf24f1f8cef16851d14a5f2e1e676b
SILGen: Fix up ownership of key path entry points for +0.
2018-03-09 16:24:08 -08:00
Karoy Lorentey
ab0c74b85c Merge pull request #14913 from lorentey/resilient-hashing
Switch to a resilient hashing interface, currently implementing SipHash-1-3.
Compiler-synthesized Hashable conformances still use the old _combineHashValues interface for now.
2018-03-09 19:57:03 +00:00
Joe Groff
ad79b5c752 SILGen: Fix up ownership of key path entry points for +0. 2018-03-09 11:52:39 -08:00
Michael Gottesman
26b9acecc1 Merge pull request #15098 from gottesmm/pr-f309e803f5f44c142f6aa97a7f91950512ab47d4
[+0-all-args] Make sure that when we use RValue::addElement to combin…
2018-03-09 10:39:16 -08:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
Karoy Lorentey
f8ce96273e [stdlib] Implement _hash(into:) for standard Hashable types. 2018-03-09 14:35:22 +00:00
Michael Gottesman
7c90e70913 [+0-all-args] Make sure that when we use RValue::addElement to combine tuples into RValues, all non-trivial values are either all +1 or +0.
Otherwise, we hit assertions since we require RValues to be consistent about +1
and +0.

This is tested by tests updated for +0.

rdar://34222540
2018-03-08 18:28:33 -08:00
Joe Groff
2d194e7765 Merge pull request #15034 from jckarter/keypath-resilience-silgen
SILGen: Emit property descriptors for (some) decls that need them.
2018-03-07 16:49:36 -08:00
Joe Groff
a8e3c4fc8b SILGen: Emit property descriptors for (some) decls that need them.
If a property or subscript is referenceable from other modules, we need to give it a descriptor so that we can reliably build an equivalent key path in or out of that module.

There are some cases that we should handle but don't yet:

- Global and static properties ought to be key-path-able someday, so we should make descriptors for them, but this might need a new key path component kind.
- Subscripts with indexes that aren't Hashable in the current module ought to get descriptors too, in case we ever support non-hashable key path components, and also because a generic subscript might be substituted with Hashable types by an external user, or an external module might post-hoc extend a type to be Hashable, so we really need to change things so that the client supplies the hashing and equality implementations for the indexes instead of the descriptor.
2018-03-07 15:32:12 -08:00
Arnold Schwaighofer
89e972f5a8 SILGen: Implement withoutActuallyEscaping verification
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
2018-03-07 09:00:12 -08:00