Commit Graph

220 Commits

Author SHA1 Message Date
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Owen Voorhees
9222dfdd46 [Sema] Fix protocol refinement access control message (#26855)
Previously, the protocol refinement access control error
would always assume a protocol was being refined. Change it
to instead refer to the appropriate declaration kind.

Resolves SR-9195
2019-08-29 17:47:24 -07:00
Daniel Rodríguez Troitiño
e722637c01 Mark implicit_tupling_untupling_codegen as executable.
Test was broken in Android CI because the CI cannot execute executable
tests, and need to be skip using this tag.
2019-08-20 18:44:49 -07:00
Pavel Yaskevich
c54913f786 [TypeChecker] NFC: Fix some diagnostics improved by porting contextual mismatches to new framework 2019-08-13 11:55:08 -07:00
Varun Gandhi
881de8816d Add codegen test cases to make sure that patching patterns works.
There is a small chance that codegen and everything works fine, but the
generated code is wrong because of mismatched expectations on two sides,
so we have some tests to catch that.
2019-08-12 09:58:22 -07:00
Slava Pestov
25e4ca9a60 AST: Simplify Optional default initialization behavior 2019-07-16 14:26:54 -04:00
gregomni
92eb874e0e Insert access level fixits in front of 'override', if it's there, instead of
after. This is so that code produced by this fixit matches the same keyword
order as code produced by autocompleting a method decl in a new subclass.
2019-06-27 06:57:02 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Slava Pestov
fb5c8ce6cc Sema: Check warning messages in test/Compatibility/attr_override_lazy.swift 2019-05-14 19:18:58 -04:00
Pavel Yaskevich
860cddfd34 [ConstraintSystem] Allow arguments to be passed by value to @autoclosure parameters
Instead of always requiring a call to be made to pass argument
to `@autoclosure` parameter, it should be allowed to pass argument
by value to `@autoclosure` parameter which can return a function
type.

```swift
func foo<T>(_ fn: @autoclosure () -> T) {}
func bar(_ fn: @autoclosure @escaping () -> Int) { foo(fn) }
```
2019-05-08 19:41:35 -07:00
Slava Pestov
0502f3b22e Slim down test/Compatibility/tuple_arguments_4.swift 2019-04-16 22:10:22 -04:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Jordan Rose
d36a7393b0 Fix issue with expression patterns in switch exhaustivity checking (#23804)
Expression patterns (and cast patterns) don't actually contribute to
the exhaustivity of a switch statement---if you're matching against a
String, matching "abc" doesn't meaningfully reduce the full space of
the values you have to match. This was already handled, but didn't do
the right thing in a particular case involving a tuple payload in an
enum after the Space Engine (exhaustivity checker) optimizations that
went out in Swift 5.

https://bugs.swift.org/browse/SR-10301
2019-04-05 09:14:54 -07:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
David Zarzycki
31d8153097 [Sema] QoI: Report all tuple type resolution errors
This improves single pass diagnostics when more than one tuple type
element has problems.
2019-03-11 16:03:17 -04:00
Slava Pestov
780612cf03 Merge pull request #22800 from slavapestov/witness-access-check-crash
Sema: Fix crashes in witness access control checking
2019-02-22 21:21:47 -05:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Slava Pestov
cde5c6faa6 Remove obsolete test that wasn't being run 2019-02-22 14:03:39 -05:00
Slava Pestov
6d19f7e0f4 Sema: Fix inconsistent behavior with SE-0110-related compatibility hack
Back when SE-0110 was implemented we decided that passing a function value
taking multiple parameters would be allowed where a function value taking
a single tuple argument was expected.

Due to quirks in the old function type representation, the "splat" in the
other direction sometimes worked too. When we redid the function type
representation we added a simulation of the old quirk for -swift-version 4
mode.

However this simulation was itself problematic because it only worked when
the function value being passed was a non-overloaded declaration reference.

Slightly broaden the hack to the overloaded case, to prevent user
confusion when adding or removing overloads.
2019-02-21 09:57:03 -05:00
Ding Ye
0f493a68b3 [Sema] Improve diagnostics for access level of protocol witness in extension. (#22235)
If the access level of a protocol witness does not satisfies a requirement,
the compiler suggests marking it as the required level.  This is not suitable
when the witness is in an extension whose specified access level is less than
the required level, since the fixit fights with other warnings in this case.
This patch identifies such case and produces improved diagnostics.

Resolves: SR-9793
2019-02-08 09:31:01 -08:00
Jordan Rose
3c740e4f2e Don't fix access of an 'open' decl in a 'public' extension
This is reasonable to diagnose with a warning, but dropping the 'open'
down to 'public' isn't the right fix, because now it's not a valid
override. The declaration has to get moved to another extension instead,
or the extension has to not set a default access level.

This turned out to be a source compat issue because the same logic
that emits the fix-it also updates the access of the member, which
then resulted in "must be as accessible as the declaration it
overrides" in the /same/ build. It's not immediately clear what caused
this; probably something's just being validated in a different order
than it was before. The change makes sense either way.

Stepping back, it's weird that a warning would change how the compiler
saw the code, and while we could check for 'override' explicitly, we
can't know if the member might be satisfying a protocol requirement.
Better to just not guess at the right answer here.

rdar://problem/47557376&28493971
2019-01-28 18:25:06 -08:00
Jordan Rose
1f06cd7e6d Tweak diagnostic for a high-access member in a low-access extension
Before: declaring a public instance method in a private extension
After: 'public' modifier conflicts with extension's default access of
       'private'
2019-01-28 18:24:12 -08:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Pavel Yaskevich
46afe3bb41 [Diagnostics] NFC: Remove redundant "because" from witness_not_usable_from_inline 2018-12-20 00:53:51 -08:00
Robert Widmann
4c04a0fbbc Merge pull request #21230 from CodaFi/casein
Lift The "Large Space Heuristic" For Real This Time
2018-12-16 13:59:50 -05:00
Slava Pestov
c5cdd709ba Sema: SE-0110 tuple splatting should not implode argument list with varargs
Fixes <https://bugs.swift.org/browse/SR-9470>.
2018-12-16 01:02:56 -05:00
Slava Pestov
b8ff7f1b31 Sync up tuple_arguments and tuple_arguments_4 tests 2018-12-16 01:02:56 -05:00
Robert Widmann
3102ed0a7a Remove regression tests for the dead size heuristic 2018-12-15 23:38:35 -05:00
Robert Widmann
04c88aa822 Drop the coverage size heuristic
In light of the invocation limits placed on space subtraction, this grossly incorrect check is being dropped.

Resolves a source of miscompiles in mostly machine-generated code
including SR-6652 and SR-6316.
2018-12-15 23:19:04 -05:00
Jordan Rose
45eac2cffb Fix a hole in access control checking for var/let
Previously if a declaration had both a Type and a TypeRepr available,
we would only check the access of the TypeRepr. However, this is
incomplete when the type is partially inferred, as in

  public var inferredGenericParameters: Optional = PrivateStruct()

The new algorithm is to the Type first, then:
- if the Type is okay, move on to check the TypeRepr
- if the Type is not okay and we're in pre-Swift-5 mode, check the
  TypeRepr, and if /that's/ okay downgrade the whole thing to a
  warning.

Unfortunately, we can't /just/ check the Type in the "good" case,
because we don't always properly preserve sugar when going from a
TypeRepr that represents a typealias to the corresponding Type, and we
want to be able to fix those cases in the future. So we have to check
both.
2018-12-08 22:38:16 -08:00
Harlan Haskins
1abeeb8b92 [Sema] Diagnose internal(set) from @inlinable functions
This patch mainly consolidates the functions used to check accessors vs.
other decls, and makes sure we check setter access as well as regular
decl access.

rdar://45217648
2018-12-07 12:46:19 -08:00
Harlan Haskins
d30a3da32a [Sema] Non-requirement protocol members should inherit @usableFromInline
Previously, members of protocols that were not protocol requirements,
like accessors and typealiases, did not inherit @usableFromInline from
the parent protocol. Change this so they do.
2018-12-07 12:45:32 -08:00
Harlan Haskins
4adc80a8cf [test] Update @inlinable test to Swift 5
Also add a compatibility test for Swift 4.2 behavior
2018-12-07 12:42:05 -08:00
Pavel Yaskevich
07e5d54855 [CSDiagnostics] Add custom diagnostic for invalid @autoclosure forwarding
Suggest to add `()` (form a call) to correctly forward argument function
originated from `@autoclosure` parameter to function parameter itself
marked as `@autoclosure`.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
cc780e3292 [ConstraintSystem] Make sure that @autoclosure argument detection works for subscripts/members
Currently logic in `matchCallArguments` could only detect argument
being an @autoclosure parameter for normal calls and operators.

This patch extends it to support subscripts and unresolved member calls.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
1b37bc2a9c [TypeChecker] NFC: Switch @autoclosure compatibility test to pass swift version to RUN 2018-11-16 13:18:49 -08:00
Jordan Rose
bda28ffb9b Require @usableFromInline on witnesses for non-type requirements too (#20485)
Follow-up to f33bf67dc9 for non-type requirements. We use non-type
witnesses for optimization purposes, so if we didn't enforce this we
might end up with something silently performing worse with parseable
interfaces than it would with swiftmodules. There's also a tricky case
where the client of the interface infers a different implementation:

    public protocol Foo {
      func foo()
    }
    extension Foo {
      public func foo() { print("default") }
    }
    @usableFromInline struct FooImpl: Foo {
      internal func foo() { print("actual") }
    }

There might be another solution to this in the future, but for now
this is the simplest answer. Like f33bf67dc9, it'll be a warning in
Swift 4 mode and an error in Swift 5 mode.

rdar://problem/43824161
2018-11-15 16:59:39 -08:00
Pavel Yaskevich
6c8513fc55 [ConstraintSystem] Test @autoclosure behavior in Swift < 5 compatibility mode
Swift versions < 5 allowed argument passed to @autoclosure parameter
to be @autoclosure function type, we need to make sure that such
behavior is preserved.
2018-11-10 11:59:29 -08:00
Jordan Rose
f33bf67dc9 Require @usableFromInline on associated type witnesses
...when the protocol and the conforming type are not both public but
are both public-or-usableFromInline. It's possible to write inlinable
functions that depend on these types:

    public protocol HasAssoc {
      associatedtype Assoc
    }
    public func getAssoc<T: HasAssoc>(_: T) -> T.Assoc

    @usableFromInline struct Impl: HasAssoc {
      @usableFromInline typealias Assoc = Int
    }

    @inlinable func test() {
      let x: Int = getAssoc(Impl())
    }

rdar://problem/43824052
2018-11-06 17:00:46 -08:00
Slava Pestov
38fdb6b7ff Update various tests to not use Swift 3 code
Completely mechanical changes:

- Explicit @objc in a few places
- Some imported APIs changed
- For the mix-and-match tests, just test version 4/5 instead of 3/4
2018-10-26 20:15:01 -04:00
Greg Titus
7d0bdb112e Omit protocol match diagnosis for constructors with differing names. 2018-10-14 17:08:50 -07:00
Jordan Rose
df1ef05c4c Remove unwanted exceptions from @inlinable checking
- Treat protocol requirements just like associated types in how they
  inherit usable-from-inline-ness, rather than special-casing them in
  the check for inlinable code.

- Enum elements are already treated this way, so we can remove a
  redundant check for that.

- Finally, start enforcing that 'dynamic' declarations need to be
  '@usableFromInline' to be used in inlinable functions...in Swift 5
  mode or resilient code. I didn't even add a warning in Swift 4/4.2
  because it was illegal to use '@usableFromInline' on a 'dynamic'
  declaration in Swift 4.2. (Oops.)
2018-10-05 12:21:01 -07:00
Jordan Rose
3114ed17e1 Allow '@usableFromInline' on 'dynamic' decls
It actually /does/ make sense to enforce the usable-from-inline rules
on dynamic declarations, but that would break source compatibility at
this point. Just allow '@usableFromInline' to be written on 'dynamic'
declarations, so that it'll be compatible with Swift 5.
2018-10-05 12:20:47 -07:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Doug Gregor
cffe3869a6 Merge pull request #19034 from DougGregor/protocol-override
Introduce overrides of protocol members and drop them from witness tables
2018-09-05 20:57:21 -07:00
Jordan Rose
5dace224a0 Merge pull request #18623 from dingobye/sr8453
[Sema] Warn for redundant access-level modifiers on setters or used in an extension.
2018-09-05 17:44:26 -07:00
Doug Gregor
3ede41cf8d Update tests now that ‘override’ is allowed in protocols. 2018-09-04 16:42:06 -07:00