Commit Graph

22 Commits

Author SHA1 Message Date
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
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
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
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
Robert Widmann
2fb5afb755 Remove the @_downgrade_exhaustivity_check hack
This hack was only needed for Swift 3 mode in a narrow case.  Flush it out of the compiler so we can simplify the space engine.
2018-08-24 10:54:43 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Jordan Rose
e783027061 Space Engine: uninhabited types map to empty spaces (#17680)
Without this, the compiler ended up complaining about missing cases
that can't actually occur, like `Optional<Never>.some(_)`. This was a
regression from Swift 4.1.

https://bugs.swift.org/browse/SR-8125
2018-07-02 18:27:46 -07:00
David Ungar
41b2281c03 Update tests to new message 2018-05-02 15:49:29 -07:00
David Ungar
9c74f8108d Fix tests for new diagnostic. 2018-05-02 15:49:29 -07:00
Jordan Rose
797901fc41 Enable @unknown default warnings by default in Swift 5 mode (#16045)
Note that I said "warnings"; we're going to be more cautious about
rollout and just make this a warning in Swift 5 mode, with /no/
diagnostics in Swift 3 and 4. Users are still free to use `@unknown
default` in these modes, and they'll get a fatal run-time error if
they don't and an unexpected case actually shows up.

rdar://problem/29324688
2018-04-20 17:04:31 -07:00
Jordan Rose
a9f26ab893 Don't crash when using @unknown default with a non-enum type.
Also improve the error message when using it with a very large space.

https://bugs.swift.org/browse/SR-7408
2018-04-11 19:28:39 -07:00
Jordan Rose
7405d515be Don't include unavailable cases in switch exhaustivity checking (#15849)
At one point compiler wouldn't let you use them in matches, so people have
had to use catch-all cases instead. SILGen already handles this because of
@_downgrade_exhaustivity_check, as well as non-exhaustive enums in
Swift 4 mode.

rdar://problem/33246586
2018-04-10 14:00:14 -07:00
Jordan Rose
7c689c322e Prefer @unknown default over @unknown case _ in diagnostics
(and fix-its)
2018-04-05 17:54:49 -07:00
Jordan Rose
ceb51eea80 Clean up fix-it generation for missing cases, esp. with '@unknown'
- Combine the common logic for editor mode and non-editor mode.
- Do a better job minimizing fix-its.
- If '@unknown' is the only missing case, put `fatalError()` in the
  Xcode placeholder, since that's what the compiler would have done.
2018-04-05 16:35:15 -07:00
Jordan Rose
bdb8388721 Allow '@unknown' to match any enums not explicitly marked frozen
If a client wants to defend themselves against new cases in libraries
they use, or even in their own code, they're allowed to.
2018-04-05 16:35:15 -07:00
Jordan Rose
2a0f9c3eb0 '@unknown' can match unknown cases in nested positions
That is, when matching non-frozen enums at non-top-level positions:

    switch (nonFrozenEnum1, nonFrozenEnum2) {
    case (.singleKnownCase1, .singleKnownCase2): ...
    unknown: ...
    }

...it's sufficient to use '@unknown' to match

  (.singleKnownCase1, .someFutureCase2)
  (.someFutureCase1, .singleKnownCase2)
  (.someFutureCase1, .someFutureCase2)
2018-04-05 16:35:15 -07:00
Jordan Rose
054658b316 Downgrade exhaustivity errors to warnings if '@unknown' is present
The other half of '@unknown' in Sema. Again, the diagnostics here
could be improved; rather than a generic "switch must be exhaustive",
it could say something about unknown case handling known cases.

One interesting detail here: '@unknown' is only supposed to match
/fully/ missing cases. If a case is /partly/ accounted for, not
handling the rest is still an error, even if an unknown case is
present.

This only works with switches over single enum values, not values that
contain an enum with unknown cases. That's coming in a later commit.
(It was easier to get this part working first.)
2018-04-05 16:35:14 -07:00
Jordan Rose
3e2411acd4 Diagnose when switching on a non-frozen enum without a catch-all case
The first half of Sema support for '@unknown'. The other part is
handling when the user /does/ write '@unknown', which results in
/other/ things being downgraded to warnings.

The diagnostics here are still pretty minimal; they should explain
what's going on with '@unknown' to someone who hasn't read the Swift 5
release notes.
2018-04-05 16:35:14 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Jordan Rose
00361df52b Put non-frozen enum exhaustivity diagnostics behind a frontend flag
...spelled '-enable-nonfrozen-enum-exhaustivity-diagnostics'. This
is for staging purposes.
2018-03-20 10:39:02 -07:00
Jordan Rose
7c60f1c895 Diagnose uncovered switches on non-frozen enums
Warn in Swift 4 mode and error in Swift 5 mode when switching on a
non-frozen enum without providing a default case.

Note that this is a preliminary implementation, in order to test the
rest of the feature.
2018-03-20 10:39:02 -07:00