Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplementation for /most/ of SE-0192 (frozen and non-frozen enums) #14945
Conversation
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test source compatibility |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test compiler performance |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
Build comment file:Compilation-performance test failed |
jrose-apple
force-pushed the
jrose-apple:frozen-enums
branch
Mar 3, 2018
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test compiler performance |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test source compatibility |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test source compatibility |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test compiler performance |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
Build comment file:Compilation-performance test failed |
jrose-apple
force-pushed the
jrose-apple:frozen-enums
branch
Mar 5, 2018
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
Build failed |
jrose-apple
force-pushed the
jrose-apple:frozen-enums
branch
Mar 5, 2018
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please clean test macOS |
This comment has been minimized.
This comment has been minimized.
Build failed |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test macOS |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test compiler performance |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test source compatibility |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
jrose-apple
added some commits
Sep 14, 2017
jrose-apple
force-pushed the
jrose-apple:frozen-enums
branch
Mar 20, 2018
This comment has been minimized.
This comment has been minimized.
Rebased. @swift-ci Please test |
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test source compatibility |
jrose-apple
changed the title
[WIP] Implementation for SE-0192 (frozen and non-frozen enums)
Implementation for /most/ of SE-0192 (frozen and non-frozen enums)
Mar 20, 2018
DougGregor
approved these changes
Mar 20, 2018
This looks good. The space engine part is appropriately mind-boggling, but I've convinced myself it looks good. Nice work! |
@@ -1101,7 +1101,7 @@ public struct CodingUserInfoKey : RawRepresentable, Equatable, Hashable { | |||
//===----------------------------------------------------------------------===// | |||
|
|||
/// An error that occurs during the encoding of a value. | |||
@_fixed_layout // FIXME(sil-serialize-all) | |||
@_frozen // FIXME(sil-serialize-all) |
This comment has been minimized.
This comment has been minimized.
DougGregor
Mar 20, 2018
Member
This is a surprise to me; why should encoding and decoding errors be frozen? I'd expect this to grow over time, like most error types.
This comment has been minimized.
This comment has been minimized.
jrose-apple
Mar 20, 2018
Author
Member
They'll definitely get un-frozen. This commit did not remove any frozen
s that were currently there.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
public enum _DebuggerSupport { | ||
@_fixed_layout // FIXME(sil-serialize-all) | ||
@_frozen // FIXME(sil-serialize-all) | ||
@_versioned // FIXME(sil-serialize-all) | ||
internal enum CollectionStatus { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Name: EnumExhaustivity | ||
Tags: | ||
- Name: RegularEnumTurnedExhaustiveThenBackViaAPINotes | ||
EnumExtensibility: open |
This comment has been minimized.
This comment has been minimized.
DougGregor
Mar 20, 2018
Member
I'd never seen this cute "no newline at end of file" GitHub graphic before
@@ -239,6 +242,10 @@ namespace swift { | |||
/// Diagnose uses of NSCoding with classes that have unstable mangled names. | |||
bool EnableNSKeyedArchiverDiagnostics = true; | |||
|
|||
/// Diagnose switches over non-frozen enums that do not have catch-all | |||
/// cases. | |||
bool EnableNonFrozenEnumExhaustivityDiagnostics = false; |
This comment has been minimized.
This comment has been minimized.
DougGregor
Mar 20, 2018
Member
This is for staging while we settle on the "unknown case" spelling, right? It'll go away then?
This comment has been minimized.
This comment has been minimized.
jrose-apple
Mar 20, 2018
Author
Member
It's mainly so I can land this part before SE-0192's review period ends, but yes.
slavapestov
reviewed
Mar 20, 2018
Please add some code generation (SILGen) tests for -enable-testing. I imagine we'll want to trap if the original library evolves resiliently, right? Also, library evolution tests for non-frozen @objc enums to ensure the unknown case is handled properly. |
|
||
// All other checks are use-site specific; with no further information, the | ||
// enum must be treated non-exhaustively. | ||
if (!useDC) |
This comment has been minimized.
This comment has been minimized.
slavapestov
Mar 20, 2018
Member
Do we ever need to check exhaustiveness in SILGen or anything else that runs after Sema? Because we won't have a useDC anymore
This comment has been minimized.
This comment has been minimized.
jrose-apple
Mar 20, 2018
Author
Member
I think we'll have a DC up through SILGen, but you do have me worried about optimizations. Unfortunately we don't actually the right API for that ("AvailabilityContext"); fortunately, it'll err on the side of "non-exhaustive". (That is, passing nullptr
or the containing module or the containing source file might answer "non-exhaustive" when it could be "exhaustive", but never the other way around.)
void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) { | ||
switch (D->getModuleContext()->getResilienceStrategy()) { | ||
case ResilienceStrategy::Default: | ||
// FIXME: Don't warn about the use of this attribute in the standard |
This comment has been minimized.
This comment has been minimized.
slavapestov
Mar 20, 2018
Member
You might be able to get away with removing this now that resilience is on
This comment has been minimized.
This comment has been minimized.
@@ -121,25 +127,25 @@ namespace { | |||
// potentially push an enormous fixit on the user. | |||
static const size_t MAX_SPACE_SIZE = 128; | |||
|
|||
size_t computeSize(TypeChecker &TC, | |||
size_t computeSize(TypeChecker &TC, const DeclContext *DC, |
This comment has been minimized.
This comment has been minimized.
slavapestov
Mar 20, 2018
Member
It's awkward to plumb the DC (and TC) through everything here -- can't we make them instance variables?
This comment has been minimized.
This comment has been minimized.
jrose-apple
Mar 20, 2018
Author
Member
Sure, that makes sense. I'll save it for the next half, though, where I implement unknown:
.
@@ -1101,7 +1101,7 @@ public struct CodingUserInfoKey : RawRepresentable, Equatable, Hashable { | |||
//===----------------------------------------------------------------------===// | |||
|
|||
/// An error that occurs during the encoding of a value. | |||
@_fixed_layout // FIXME(sil-serialize-all) | |||
@_frozen // FIXME(sil-serialize-all) |
This comment has been minimized.
This comment has been minimized.
jrose-apple
added some commits
Dec 15, 2017
This comment has been minimized.
This comment has been minimized.
We do have the "evolution" tests for non-frozen enums by testing private cases, but I'll add the ones for |
This comment has been minimized.
This comment has been minimized.
@jrose-apple The case I'm thinking of is when you switch over an @objc non-frozen enum, we want to make sure we don't hit UB if you pass in an unknown case |
This comment has been minimized.
This comment has been minimized.
Sorry, I forgot that one already landed. :-) See #14724. |
jrose-apple
force-pushed the
jrose-apple:frozen-enums
branch
to
348f966
Mar 20, 2018
This comment has been minimized.
This comment has been minimized.
Addressed feedback. @swift-ci Please smoke test |
This comment has been minimized.
This comment has been minimized.
Merging even though the proposal is still in review in order to get some living-on (and so that I don't have to keep rebasing it). Note that the diagnostics are still off and |
jrose-apple commentedMar 3, 2018
An alternative to #11961 that only makes a frozen / non-frozen distinction for imported C enums and for Swift enums in the stdlib/overlays. (Really, it's "libraries compiled with
-enable-resilience
", and exactly what that means has not been discussed publicly and is not part of SE-0192.)This does not include the implementation of
unknown case
, or whatever we end up naming it. That's a big enough change on its own that it deserves its own PR, and this part can land first.The diagnostics part of this is behind a frontend flag,
-enable-nonfrozen-enum-exhaustivity-diagnostics
.