Commit Graph

3309 Commits

Author SHA1 Message Date
Holly Borla
66e85721cb Merge pull request #30807 from hborla/property-wrapper-refactoring
[Property Wrappers] Refactor property wrappers so the synthesized backing init is only type checked once
2020-04-14 10:48:22 -07:00
Slava Pestov
ab45d517d5 Merge pull request #29931 from theblixguy/fix/SR-12178
[Typechecker] Fix _modify for wrapped properties with observers
2020-04-12 22:11:10 -04:00
Suyash Srijan
4688f4de64 [Test] Add a SILGen test to make sure the observers are correctly called 2020-04-10 21:32:28 +01:00
Hamish Knight
a61223a255 [CS] Visit all fixed bindings for constraint re-activation (#30886)
[CS] Visit all fixed bindings for constraint re-activation
2020-04-10 12:27:47 -07:00
Hamish Knight
d69a42d656 [CS] Preserve compatibility for collection coercions
Previously we could allow some invalid coercions to
sneak past Sema. In most cases these would either
cause crashes later down the pipeline or
miscompiles. However, for coercions between
collections, we emitted somewhat reasonable code
that performed a force cast.

This commit aims to preserve compatibility with
those collection coercions that previously
compiled, and emits a warning telling the user to
use either 'as?' or 'as!' instead.
2020-04-10 10:16:07 -07:00
Slava Pestov
8ee5d2931f Sema: Force property wrappers in EmittedMembersRequest::evaluate()
Fixes <rdar://problem/61229365>.
2020-04-09 19:57:12 -04:00
Suyash Srijan
724f8c23db [Typechecker] Implement SE-0268 Refine didSet Semantics (#26632) 2020-04-09 01:23:15 +01:00
Doug Gregor
78880ffc1a Merge pull request #27776 from owenv/catch_revamp_take_4
[SE-0276] Support multiple patterns in catch clauses
2020-04-07 12:31:33 -07:00
Slava Pestov
dbaa61953e AST: Fix accessibility checking in opaque type archetype substitution logic
We were failing to replace opaque types with their underlying type
upon encountering an internal type from the current module. This
could happen when the internal type appeared in generic substitutions,
for example when calling a protocol extension method.

Fixes <rdar://problem/60951353>.
2020-04-07 12:13:38 -04: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
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
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
Slava Pestov
e5a7fd3114 Merge pull request #30802 from slavapestov/var-decl-usage-checker-fixes
VarDeclUsageChecker fixes
2020-04-03 23:25:19 -04: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
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
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
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
Joe Groff
90062f1839 Sema: Infer error convention from @objc protocol requirements.
When a Swift declaration witnesses an ObjC protocol requirement, its error convention needs to
match the requirement. Furthermore, if there are different protocol requirements that the
Swift method can witness, with different error conventions, we need to bail out because we
can't simultaneously match all of them. Fixes rdar://problem/59496036 | SR-12201.
2020-04-01 18:26:38 -07:00
Slava Pestov
7b4786e723 Sema: Contextualize closures for function builder bodies also
The ContextualizeClosures walker re-parents and assigns discriminators to
autoclosures. We weren't doing this walk for function builder bodies,
which meant that proper invariants were not being established for the
implicit autoclosures synthesized for partially applied method references.

This is a recent regression from my change to build curry thunks for
unapplied method references in Sema.

Fixes <rdar://problem/61039516>.
2020-04-01 15:42:25 -04:00
Slava Pestov
52c11c78d1 Sema: Property wrapper storage wrappers ($foo) inherit 'final' bit from original property
Otherwise, we would generate inconsistent vtable layouts for classes
with static properties that have attached wrappers. The reason is that
we normally force synthesis of the backing storage and storage wrapper
for each instance property wrapper as part of computing the lowered
stored properties.

However, there was no such forcing for static properties. But since a
static stored property (with an attached wrapper or otherwise) must be
'final', the real fix is to just ensure that the 'final' bit propagates
to the storage wrapper as well.

The backing storage property was already always final, so the issue
did not arise there.

Fixes <rdar://problem/59522703>, <https://bugs.swift.org/browse/SR-12429>.
2020-03-31 23:42:34 -04:00
Suyash Srijan
f724d1ff85 [SE-0280] Enum cases as protocol witnesses (#28916)
* [Typechecker] Allow enum cases without payload to witness a static get-only property with Self type protocol requirement

* [SIL] Add support for payload cases as well

* [SILGen] Clean up comment

* [Typechecker] Re-enable some previously disabled witness matching code

Also properly handle the matching in some cases

* [Test] Update typechecker tests with payload enum test cases

* [Test] Update SILGen test

* [SIL] Add two FIXME's to address soon

* [SIL] Emit the enum case constructor unconditionally when an enum case is used as a witness

Also, tweak SILDeclRef::getLinkage to update the 'limit' to 'OnDemand' if we have an enum declaration

* [SILGen] Properly handle a enum witness in addMethodImplementation

Also remove a FIXME and code added to workaround the original bug

* [TBDGen] Handle enum case witness

* [Typechecker] Fix conflicts

* [Test] Fix tests

* [AST] Fix indentation in diagnostics def file
2020-03-28 10:44:01 +00: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
Doug Gregor
a15a905425 [Property wrappers] Expand testing for backing initializer linkage change. 2020-03-23 15:59:29 -07:00
Doug Gregor
8621a524ba [Property wrappers] Fix property wrapper backing initializer linkage.
Have property wrapper backing initializers determine their linkage in
the same way as stored property initializers, which need to match the linkage
of the enclosing type in cases where one can write an initializer
outside of the source file where that type is declared.

Fixes rdar://problem/59607192.
2020-03-23 14:27:25 -07:00
Doug Gregor
aacdd3a27d Merge pull request #30537 from DougGregor/roop-sr10950_prop_wrap_autoclosure
[Property wrappers] Fix handling of @autoclosure in init(wrappedValue:)
2020-03-20 23:12:18 -07:00
Anthony Latsis
7e21d7b5eb Merge pull request #30423 from AnthonyLatsis/se-0267-additions
[SE-0267] Improvements (Ep. 1)
2020-03-21 08:59:13 +03:00
Anthony Latsis
14d3687d3b [SILGen] Test vtable thunk emission for overrides with contextual where clauses 2020-03-21 05:46:47 +03:00
Doug Gregor
32be6f58f6 [Property wrappers] Handle composition and autoclosures.
Fixes the test case from rdar://problem/58986940.
2020-03-20 16:56:34 -07:00
Doug Gregor
af1abea57a [Property wrappers] Fixup SILGen test for @autoclosure support. 2020-03-20 12:21:51 -07:00
Roopesh Chander
a5f1da27d0 [Property wrappers] New tests for @autoclosure handling 2020-03-20 12:21:51 -07:00
Roopesh Chander
87443fa5fc [Property wrappers] Update existing tests for @autoclosure handling 2020-03-20 12:21:51 -07:00
Arnold Schwaighofer
26af2d7569 Merge pull request #30516 from aschwaighofer/silgen_fix_assign_by_wrapper_objc_dynamic
SILGen: Fix assign_by_wrapper of ``@objc dynamic`` properties
2020-03-20 06:51:39 -07:00
Arnold Schwaighofer
57c6c59ad6 SILGen: Fix assign_by_wrapper of `@objc dynamic` properties
Insert a thunk. Objc method calls might need bridging.

rdar://60038084
2020-03-19 15:09:19 -07:00
Slava Pestov
a618c73b9a Re-apply: Add regression test for rdar://59496033 2020-03-19 16:23:30 -04:00
Slava Pestov
fcf3118417 Merge pull request #30499 from slavapestov/remove-curried-declrefs
SIL: Remove curried SILDeclRefs
2020-03-19 14:59:47 -04:00
Mishal Shah
cfc7adef10 Revert "Add regression test for rdar://59496033" 2020-03-19 09:31:59 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Slava Pestov
f6187e520a Sema: Don't devirtualize partially applied operator references 2020-03-18 19:23:18 -04:00
Slava Pestov
c061e66927 Add regression test for rdar://59496033 2020-03-18 16:11:07 -04:00
Slava Pestov
c543838854 Sema: Rewrite partial applications into closures
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.

Eg,

Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)

super.bar => { args... in super.bar(args...) }

With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.

This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.

This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.

A follow-up cleanup will remove the SILGen curry thunk
implementation.

Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
2020-03-18 09:29:22 -04:00
Michael Gottesman
7ac7620c78 Merge pull request #30425 from gottesmm/pr-a62f3926b9e0b421c35408e66cf592f84295cd24
[ownership] Treat open_existential_box as an interior pointer producting instruction.
2020-03-16 14:06:15 -07:00
eeckstein
b5c0b6de9d Merge pull request #30381 from eeckstein/lazy_properties
Improve optimization of lazy properties.
2020-03-16 08:32:19 +01:00
Michael Gottesman
f3df836652 [ownership] Treat open_existential_box as an interior pointer producting instruction.
This means that it can only have a guaranteed object as an operandand that we
validate that all uses of the result address of open_existential_box occur only
within the lifetime of said object's borrow scope.
2020-03-15 23:21:45 -07:00
Meghana Gupta
8e800e49bf Recommit #29812 with fixes (#30342) 2020-03-13 19:34:16 -07:00
Saleem Abdulrasool
2e134289d3 Merge pull request #30364 from compnerd/windows-filenames
test: adjust the test to improve the viability on Windows
2020-03-13 07:54:54 -07:00
Erik Eckstein
2de425665c PerformanceInliner: prevent inlining of lazy property getters
Lazy property getters are usually non tivial functions (otherwise the user would not implement it as lazy property).
Inlining such getters would most likely not benefit other optimizations because the top-level switch_enum cannot be constant folded in most cases.
Also, not inlining lazy property getters enables optimizing them in CSE.
2020-03-13 09:49:56 +01:00
Erik Eckstein
ae93e60072 SIL: add a lazy_property_getter flag to SILFunction
It is set on getter-functions for lazy properties.
2020-03-13 09:49:55 +01:00
Joe Groff
719002b08e Merge pull request #30365 from jckarter/substitution-map-mismatches
Create an inherited conformance in SubstitutionMap::lookupConformance when needed.
2020-03-12 08:39:44 -07:00