Commit Graph

187 Commits

Author SHA1 Message Date
Huon Wilson
b1115af1eb Switch a pile of VarDecl::Specifier::Owneds to ::Default.
A lot of these probably should be Owned, but deciding that is work for
another time.
2018-03-08 12:36:37 +11:00
gregomni
ebdbe6e9fb Code to derive Codable was assuming any decl of the desired key would be a
VarDecl, now does the right thing in the presence of identically named other
declarations (like nested types).
2018-02-11 19:16:38 -08:00
Mark Lacey
2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Doug Gregor
ffe79e047f [Codable] Remove compiler hack faking conditional conformances.
The Codable synthesis code was checking the conditional requirements of
Optional/Array/Set/Dictionary's Codable conformances, which had to be
unconditional. Now that they are properly conditional conformances, we
no longer need the hack.

Thanks to @itaiferber for pointing this out!
2017-11-30 11:47:12 -08:00
swift-ci
abe34f804b Merge pull request #11902 from itaiferber/factor-out-isdefaultinitializable 2017-09-20 11:32:39 -07:00
Itai Ferber
cda3bf19aa Factor isDefaultInitializable logic for reuse
Factors isDefaultInitializable logic from
TypeChecker::addImplicitConstructors (and others) so it can be reused
for Codable synthesis.
2017-09-20 09:45:25 -07:00
Slava Pestov
39872d9a96 Sema: Remove "at least internal" check for derived conformance declarations
It looks like at some point derived conformances were in their own
FileUnit, but this is no longer the case.
2017-09-17 21:35:55 -07:00
Itai Ferber
f90827e17b Codable: excluded vars shouldn’t need explicit val
Properties of Codable types which are optional and excluded via the CodingKeys enum should not require an explicit nil assignment, since in all other cases, optional vars get a default value of nil.
2017-09-11 10:29:07 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Itai Ferber
4c366d8efe Merge pull request #11045 from itaiferber/codable-class-fixes
Codable Class Fixes
2017-07-24 15:42:45 -07:00
Itai Ferber
071caf263a Additional responses to feedback
* Make Decodable synthesis lazy again
* Remove side effects from assertions
* Assert on superclass failable initializers (and verify via a unit test)
* Fix space typo
* Remove more needless instances of single-element arrays
* Unambiguously refer to init() in unit tests
* Add failable superclass init tests and a test to ensure Decodable fails to be inherited when superclass synthesis fails
* Add tests for structs to ensure they receive no-argument initializers where appropriate
2017-07-24 08:02:19 -07:00
Robert Widmann
e5918f70e8 [NFC] Refactor self type computation to return a Param
Remove a user of InOutType::get and flip a few users of
FunctionType::get to pass Params instead of naked input
types.
2017-07-23 21:36:16 -07:00
Itai Ferber
a30e9117e6 Responses to feedback
* Use `isSpecificProtocol` instead of `==`
* Synthesize Encodable implementation lazily
* Don’t mark conformances as Used when they don’t need to be
* Avoid creating explicit one-element arrays
* Use lookupDirect instead of walking AST manually
* Produce diagnostic for Decodable classes whose non-Decodable superclass has a failable init
* Filter lazy vars manually since getStoredProperties() does not always do so
* Amend Decodable class diagnostic text
* Check for enum RawType errors only if the type was already validated
* Update unit tests to match changes
2017-07-20 08:06:21 -07:00
Itai Ferber
1f8f1fea50 Allow overriding synthesized Decodable impl.
Classes which receive a synthesized Decodable implementation should be able to subclass non-Decodable classes (if the superclass has an accessible init()) method.

Also improve diagnostics when this is not the case.
2017-07-20 07:55:09 -07:00
Itai Ferber
3d4bef7ec4 Stylistic cleanup 2017-07-20 07:55:09 -07:00
Slava Pestov
737174fe9f AST: Add a DeclContext field to ComponentIdentTypeRepr
Plumb this through and set it appropriately, but don't use it
for anything yet.
2017-07-18 22:10:33 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Itai Ferber
c277aa16b5 Merge pull request #10321 from itaiferber/weak-unowned-codable-conformance
Allow synthesis of Codable for weak/unowned vars
2017-06-16 14:19:52 -07:00
Itai Ferber
238a7a281e Allow synthesis of Codable for weak/unowned vars
The type of non-strong properties is wrapped in a ReferenceStorageType,
which does not conform to Codable. This needs to be unwrapped so the
inner reference type can be considered for Codable conformance.
2017-06-16 10:42:27 -07:00
Itai Ferber
5d663e7cf3 Indentation + style fixes 2017-06-14 13:34:21 -07:00
Itai Ferber
ea5f4e03ce Collate Codable diagnostics for correct ordering
Codable failures produced diagnostics and notes explaining what failed
during decode. These diagnostics were being output as they were
generated, which was suboptimal because it meant that NOTEs could be
produced before the error they were related to.

This was bad for consumers like Xcode, which associate NOTEs with the
last error or warning diagnostic.

This collates these notes using a diagnostic transaction and only
outputs the errors if something goes wrong.
2017-06-14 13:34:21 -07:00
Jordan Rose
4468ad2028 [Sema] Preparations for removal of getName on ValueDecl (#9972)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 22:36:39 -07:00
Slava Pestov
b3a6b852fc Merge pull request #9870 from slavapestov/unbound-generic-type-cleanup
Sema: Refactoring unbound generic types in expression context
2017-05-23 12:57:34 -07:00
Slava Pestov
7ec163a83a Parse: Simplify parsing of generic types
Now that preCheckExpression() can handle more cases, we can
eliminate a special case where sometimes we would make
DeclRefExprs instead of TypeExprs for references to generic
types.
2017-05-23 02:10:03 -07:00
Itai Ferber
9988624843 Add explicit support for IUOs
Since implicitly unwrapped optional types do not reflect conformances
added to Optional, we need to explicitly allow and handle them.
2017-05-22 14:05:09 -07:00
Itai Ferber
dd0bf0ee83 Clean up Codable synthesis slightly
Following feedback in https://github.com/apple/swift/pull/9758:
* Use a struct type for the result of hasValidCodingKeysEnum
* Use an enum type for the result of
* Skip fetching a canonical type before calling getAnyNominal()
  (getAnyNominal() looks through sugar already)
* No need to cast to IterableDeclContext (or DeclContext, even)
2017-05-22 13:21:49 -07:00
Itai Ferber
26d0d5defe Synthesize *IfPresent calls for Optional values
Optional properties now get synthesized encodeIfPresent(...) and
decodeIfPresent(...) calls (to avoid encoding needless information, and
to be more accepting on input).
2017-05-22 12:17:21 -07:00
Itai Ferber
91a8aaa0f4 Prevent synthesis for non-Codable stdlib types
Optional, Array, Set, and Dictionary currently all conform to Codable
regardless of the type they are generic on. Until conditional
conformance lands and we can rely on their conditional conformance, we
want to prevent Codable derived conformance if a type contains a
property of one of these types when we know it's actually going to fail
at runtime.
2017-05-22 09:29:36 -07:00
Itai Ferber
5eb58ef8d4 Improve experience of derivation of Codable types
* Introduce diagnostics that explain why derivation of
  Encodable/Decodable fail rather than just silently failing
* Allow properties with default values to be omitted from CodingKeys
  enum and from encoding/decoding
* If `CodingKeys` is a typealias, reach through it more consistently to
  get at the final target type
* Add unit tests to confirm this new behavior for classes and structs

NOTE: Although this made the diff bigger, standalone variables named
"type" have been renamed to "target" throughout, since the word "type"
may be ambiguous and makes debugging impossible. "target" is unique.
2017-05-19 09:45:54 -07:00
practicalswift
fff77b01c7 [gardening] Remove unused variables 2017-05-05 17:03:02 +02:00
Itai Ferber
4c2320724e Fix init(from:) required condition 2017-04-27 12:44:41 -07:00
Itai Ferber
3e6eb8f20a Derive encoding an empty container by default
struct X : Codable {} should generate an encode(to:) which encodes an
empty keyed container, not an encode(to:) which does nothing
2017-04-27 10:56:19 -07:00
Itai Ferber
e2318392be Add CodingKey and *codable derived conformance
* Allow CodingKey conformance to be automatically derived for enums
  which have no raw type (with no associated values) and which have
  a raw type of String or Int.
* Allow Encodable and Decodable conformance to be automatically derived
  for classes and structs with Encodable/Decodable properties
* Add initial unit tests for verifying derived conformance
2017-04-25 13:13:35 -07:00