Commit Graph

7976 Commits

Author SHA1 Message Date
Slava Pestov
46ea929072 Sema: Remove TMF_UnwrappingOptional
We should remove the only remaining TMF flag one day too, since it looks
completely bogus.
2017-02-13 16:59:13 -08:00
Slava Pestov
e9c255bfca Sema: Better fix for banning the '() -> T' => '() -> ()?' implicit conversion
Previously we would check TMF_UnwrappingOptional flag, which does not
stick with the constraint, so it would not always persist. Now, add a
new OptionalPayload locator element, which is more correct.

Fixes <rdar://problem/30429709>.
2017-02-13 16:59:09 -08:00
practicalswift
6daa23fa8e [gardening] Fix a vs an typos 2017-02-13 14:45:16 +01:00
Hugh Bellamy
cb3bdcc2a3 Merge pull request #7408 from hughbe/llvm-fallthrough
Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH
2017-02-13 17:39:59 +07:00
Slava Pestov
f0ecd1c1a3 Sema: Lift unnecessary restriction on initializers defined in extensions of resilient protocols
The restriction only applies to initializers in extensions of
concrete types; protocol extension initializers are OK.

Fixes <rdar://problem/30351393>.
2017-02-13 00:24:13 -08:00
Slava Pestov
0f8932cad1 Sema: Clean up the RequirementEnvironment's SubstitutionMap construction
Instead of calling addSubstitution() and addConformance(), use
GenericSignature::getSubstitutionMap().
2017-02-12 01:42:35 -08:00
Slava Pestov
9331d3f5bb AST: Remove unnecessary SubstOptions() parameters to Type::subst() 2017-02-12 00:51:27 -08:00
Slava Pestov
5296d02485 AST: More include-what-you-use gardening 2017-02-12 00:51:26 -08:00
Slava Pestov
ec4a95be21 AST: Witness stores SubstitutionList instead of SubstitutionMap
This simplifies serialization and removes some calls of
SubstitutionMap::addSubstitution() and addConformance().
2017-02-12 00:51:26 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Doug Gregor
5a031d8500 Merge pull request #6154 from DougGregor/generic-env-serialization
[Serialization] Serialize archetypes as generic environment + interface type
2017-02-10 01:30:54 -08:00
Doug Gregor
c6f6c528b1 [Type checker] Keep a type checker alive during name binding.
Name lookup can cause import of some Clang declaration, which in turn
need a type checker. Make sure a type checker exists at this time.

This is a baby step toward having the type checker always available,
which is really the end goal. For now, we need this for better generic
environment (de-)serialization.
2017-02-09 23:50:15 -08:00
Jordan Rose
df63c36b72 When setting a willSet/didSet param's type, also set the TypeLoc (#7377)
We don't actually need the TypeLoc for anything, but it was still
getting type-checked, which means it doesn't get the benefit of
inference from the initial value. In some cases the actual type of the
ParamDecl seems to get reset to the TypeLoc's type as well. Just do
the simple thing and set it directly ahead of time.

Fixes a source compatibility issue with Swift 3.0.

https://bugs.swift.org/browse/SR-3893
2017-02-09 19:15:21 -08:00
Doug Gregor
b412961003 [AST] Maintain type sugar in TypeMatcher. 2017-02-09 15:03:34 -08:00
swift-ci
bb874934f9 Merge pull request #7313 from huonw/requirement-signature-archetype-builder 2017-02-09 12:02:42 -08:00
Joe Groff
7b9015dcd3 Merge pull request #7345 from jckarter/raw-rep-synthesized-conformance
Sema: Treat the implicit RawRepresentable conformance for enums as `Synthesized` again.
2017-02-09 07:10:13 -08:00
swift-ci
1e7a572fe7 Merge pull request #7355 from DougGregor/partial-ordering-labels 2017-02-08 22:18:37 -08:00
Slava Pestov
707083d22f Sema: Fix crash when defining an extension of a nested type with constraints
If the nested type itself has generic constraints, we would
hit an assertion in requirement inference. Refactor some code
so that we can make the assertion more accurate.

Fixes <rdar://problem/30353095>.
2017-02-08 21:51:19 -08:00
Doug Gregor
e25244f3c6 [Type checker] Ignore argument labels when ordering declarations.
When comparing the parameters of two declarations for the purpose of
partial ordering, it doesn't make sense to compare the parameter
labels: they're dealt with separately and aren't conceptually part of
the type.
2017-02-08 20:54:25 -08:00
Huon Wilson
9b68748bdf [Sema] Conformances only need to be verified as used once. 2017-02-08 19:54:24 -08:00
Slava Pestov
a16faae73b AST: Move ProtocolConformance::getTypeWitnessByName() to ProtocolConformanceRef
I need to move some #includes around ("include what you use") to
break circularities for an upcoming refactoring.
2017-02-08 15:33:46 -08:00
Joe Groff
6d9a40f455 Sema: Treat the implicit RawRepresentable conformance for enums as Synthesized again.
This reverts part of #4038 which made the compiler consider it to be an `Explicit` conformance, breaking source code that was accepted in Swift 3.0 which declared a raw type as well as explicit conformance to `RawRepresentable` (reported as rdar://problem/30386658). While I'm here, a couple of spot fixes:

- Ensure an enum's raw value exprs are type-checked before checking conformances of any of its extensions, since the RawRepresentable conformance derivation will blow up if the raw value exprs haven't been checked. Fixes an order dependency issue if `extension Foo: RawRepresentable {}` gets checked before `enum Foo: Int { ... }`.
- Don't display the custom `enum_declares_rawrep_with_raw_type` diagnostic if the source location for the enum's inheritance clause is invalid, so that we don't emit a dislocated diagnostic.
2017-02-08 15:31:17 -08:00
Huon Wilson
74091fbcef [AST] Store and serialize a protocol's requirement signature.
This is the "canonical" representation of the type-level requirements of
a protocol, and we intend to use it pervasively in the compiler.
2017-02-08 13:08:31 -08:00
Slava Pestov
bd4f31025f AST: GenericEnvironment::mapTypeIntoContext() no longer needs to take a ModuleDecl
Now, use LookUpConformanceInSignature instead.
2017-02-07 19:25:34 -08:00
Jacob Bandes-Storch
c98e515734 [QoI] Improvements to function call & closure diagnostics (#7224) 2017-02-07 17:36:11 -08:00
Doug Gregor
575908a0e8 [Parser] Wipe out bogus generic parameters that we parsed in SIL mode.
This lets us remove a hack in the type checker that tried to avoid
looking at such generic parameters.
2017-02-07 16:14:57 -08:00
Doug Gregor
81daa1f53b [Type checker] Be more tolerant of broken initializer declarations. 2017-02-07 15:22:50 -08:00
Doug Gregor
d924849853 [Code completion] Clean up context validation.
… and make sure we validate a function declaration before type-checking it’s body.
2017-02-07 15:22:50 -08:00
Doug Gregor
a9daae2fea [Type checker] Don’t print an erroneous superclass in a diagnostic. 2017-02-07 15:22:50 -08:00
Doug Gregor
efe6175358 [Type Checker] Use GenericSignature::createGenericEnvironment().
New generic environments should be created directly from the generic
signature, without having to explicitly create an archetype
builder. Now, only the canonical archetype builders are ever used to
create a generic environment.
2017-02-07 15:22:50 -08:00
Doug Gregor
a88566cf81 Eliminate TypeChecker::createArchetypeBuilder(). NFC
We don't need this convenience function; archetype builders are easy
to create now.
2017-02-07 11:15:11 -08:00
Doug Gregor
0c76a9d828 [Archetype builder] Clean up PotentialArchetype a bit.
Clean up the representation of PotentialArchetype in a few small ways:

* Eliminate the GenericTypeParamType* at the root, and instead just
  store a GenericParamKey. That makes the potential archetypes
  independent of a particular set of generic parameters.

* Give potential archetypes a link back to their owning
  ArchetypeBuilder, so we can get contextual information (etc.) when
  needed. We can remove the "builder" arguments as a separate step.

Also, collapse getName()/getDebugName()/getFullName() into
getNestedName() and getDebugName(). Generic parameters don't have
"names" per se, so they should only show up in debug dumps.

In support of the former, clean up some of the diagnostics emitted by
the archetype builder that were using 'Identifier' or 'StringRef'
where they should have been using a 'Type' (i.e., the type behind the
dependent archetype).
2017-02-07 11:15:11 -08:00
swift-ci
ec274a1bbd Merge pull request #7298 from DougGregor/early-recursive-constraints 2017-02-06 23:28:51 -08:00
Doug Gregor
def14bfb70 [Archetype builder] Move checking for recursive constraints to finalize().
Rather than waiting until we try to form a contextual type to diagnose
recursion, perform the check while finalizing the archetype builder
itself.
2017-02-06 22:58:44 -08:00
Slava Pestov
85a8a50bee Merge pull request #7295 from slavapestov/introduce-substitution-list
AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
2017-02-06 22:36:03 -08:00
Rintaro Ishizaki
af9d16b4d9 [QoI] Improve diagnostics for unbound generic types (#7178)
Since the type is declared in other modules, we should use Decl instead
of its location.
2017-02-07 15:26:13 +09:00
Slava Pestov
24b620c1a0 Merge pull request #7296 from slavapestov/reapply-mfs-vtable-fix
Sema: Use dynamic dispatch for inout access of properties in classes
2017-02-06 22:01:31 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
1954665a95 AST: Remove more uses of SubstitutionMap::add{Substitution,Conformance}()
A new SubstitutionMap::getProtocolSubstitutions() method handles
the case where we construct a trivial SubstitutionMap to replace
the protocol Self type with a concrete type.

When substituting one opened existential archetype for another,
use the form of Type::subst() that takes two callbacks instead of
building a SubstitutionMap. SubstitutionMaps are intended to be
used with keys that either come from a GenericSignature or a
GenericEnvironment, so using them to replace opened archetypes
doesn't fit the conceptual model we're going for.
2017-02-06 20:33:39 -08:00
Rintaro Ishizaki
3d6da635d3 [TypeChecker] Early diagnose and remove 'final' in non-class context (#7179)
This prevents error dignostics at '<unknown>:0' caused by sythesized
accessors.
2017-02-07 12:30:06 +09:00
Slava Pestov
06de5d70c1 Sema: Use dynamic dispatch for inout access of properties in classes
The problem is that the derived property's materializeForSet was
being synthesized after recordOverride() was called, so the new
accessor never got setOverridenDecl() called on it.

As a result, SIL didn't know that the derived materializeForSet
should replace the vtable entry for the base class materializeForSet.

The more fundamental problem here is that even after some recent
cleanups, accessors are still sometimes type checked before
the AbstractStorageDecla and sometimes after. So things like
inferring final, dynamic and overrides have to be duplicated in
multiple places.

Fixes <https://bugs.swift.org/browse/SR-3840> and
<rdar://problem/30336146>.
2017-02-06 19:34:30 -07:00
Doug Gregor
fee89fe7c8 Merge pull request #7266 from DougGregor/generic-signature-create-env
Introduce `GenericSignature::createGenericEnvironment()`
2017-02-06 16:24:47 -08:00
Joe Groff
a58df44e2d Merge pull request #7279 from jckarter/single-element-tuple-errors
Sema: Ban single-labeled element tuples harder.
2017-02-06 15:36:01 -08:00
swift-ci
014abc3b4f Merge pull request #7088 from graydon/rdar-29684330-count-constraint-solving-memory-more-precisely 2017-02-06 14:55:55 -08:00
Jordan Rose
1c8caeb689 Handle implicit member references inside extensions of nested types. (#7241)
Within an extension, references to other members of the extended type
are permitted without qualification. This is intended to work even
when the extended type was a nested type, although members of the
enclosing type are /not/ visible in this case. In order to implement
this, the type checker pre-checks to see if there are /any/ members
with this name and then rewrites the unqualified reference to a
qualified one, based on an unresolved TypeExpr with the name of the
enclosing type. Unfortunately, if the enclosing type is a nested type,
that isn't going to work very well---we find the correct declaration,
but fail to map it into context by virtue of not realizing where it
came from. Fix this by explicitly checking for this case.

https://bugs.swift.org/browse/SR-3847
2017-02-06 14:49:49 -08:00
Joe Groff
7eaa507ced Sema: Ban single-labeled element tuples harder.
The prohibition in Swift 3.0 missed the case where the single-element tuple was wrapped in extra parens as the only argument of a function. We've ripped out parts of the type checker that try to cope with single-element tuples, and it would be risky and bug-prone to try to admit this code, so it's better to fix the ban than to try to accept the code, alas. Fixes SR-3788.
2017-02-06 13:54:32 -08:00
Graydon Hoare
9cb1c52fd8 Count constraint-solving memory more precisely, rdar://29684330 2017-02-06 13:04:19 -08:00
Jordan Rose
9fcfd0a45a Merge pull request #7201 from KingOfBrian/bugfix/SR-3665
Fix @discardableResult when invoking function with explicit namespace
2017-02-06 11:39:21 -08:00
Doug Gregor
6fadb4ca30 [Archetype builder] Teach diagnoseRemainingRenames() to use generic params. 2017-02-05 22:28:12 -08:00