Commit Graph

649 Commits

Author SHA1 Message Date
Pavel Yaskevich
261ffe4d5c Merge pull request #14100 from xedin/rdar-36449760
[ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
2018-01-25 00:57:41 -08:00
Pavel Yaskevich
a11263b156 [ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
If something that we are trying to contextually bind is a nested type inside
protocol or protocol extension, let's try to find the innermost conforming type
from the current declaration context and map Self parameter of the protocol
to that nominal type. Since nested types in protocols aren't yet implemented this
is going to result in failure, but that's better than crashing.

Resolves: rdar://problem/36449760
2018-01-24 18:21:26 -08:00
Mark Lacey
1ee740f906 Remove some disabled code to quiet the compiler build.
These will be re-enabled once IUOs are removed from the type system.
2018-01-23 17:46:29 -08:00
Mark Lacey
43aebc832e Revert "IUO: Add support for non-subscript dynamic lookup." 2018-01-10 22:53:56 -08:00
Mark Lacey
a47d1f87c1 IUO: Add support for non-subscript dynamic lookup.
The subscript case will require some additional refactoring to
support.
2018-01-10 16:36:24 -08:00
Mark Lacey
33fcd72939 IUO: Small refactoring in support of dynamic lookup and keypaths.
Small refactoring which will make supporting dynamic lookup and
keypaths easier.
2018-01-10 16:13:50 -08:00
Mark Lacey
5613d39636 IUO: Hoist the IUO disjunction creation to a better place.
We should just create the disjunction straight-away in resolveOverload
rather than doing it deep inside type variable binding.
2018-01-09 15:45:52 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Mark Lacey
41479f6334 IUO: Start creating the DeclForImplicitlyUnwrappedOptional OverloadChoice.
Use this in places where we have a decl that is marked with the
ImplicitlyUnwrappedOptionalAttr so that we can distinguish in the
solver which decls need to be potentially unwrapped in order to type
check successfully.
2018-01-04 14:00:36 -08:00
Mark Lacey
d1bb36425d IUO: Add overload choice kind for IUO decls.
Add a new OverloadChoiceKind for decls that are either IUO-typed, or
function-typed meaning that the function result type is IUO-typed.

Not currently used, so NFC.
2018-01-03 19:37:06 -08:00
Pavel Yaskevich
5d5872bb83 [CSBindings] Avoid binding type variables to collection types directly
Instead of binding collection types directly let's try to
bind using temporary type variables substituted for element
types, that's going to ensure that subtype relationship is
always preserved.

Resolves: rdar://problem/35541153
2017-12-01 23:04:19 -08:00
Doug Gregor
d8fddee726 [Type checker] Don’t simplify to an error type.
Type variables cannot be bound to error types, so don’t simplify to
them.
2017-11-29 16:12:19 -08:00
swift-ci
31f32be27e Merge pull request #13047 from xedin/fix-locators 2017-11-27 14:39:27 -08:00
Pavel Yaskevich
df0fd6abfb [ConstraintSystem] Improve type parameter requirement locators
When opening generic types with type parameter requirements,
add information about requirement location to the locator of each
generated constraint to make it easier to extract such information
if needed.
2017-11-27 13:38:38 -08:00
David Zarzycki
835d1a221c NFC: Use 'enum class' for TypeResolutionFlags 2017-11-22 09:14:33 -05:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
b6200728a6 Sema: Fix crash on invalid openUnboundGenericType()
We can't construct a nominal type with an ErrorType as a
parent, so in the bad circular case, return a Type() instead
to bail out of transform() altogether.
2017-11-14 00:07:56 -08:00
Slava Pestov
2d477d27eb Sema: Don't create redundant type variables for multiple references to the same closure parameter type 2017-10-20 23:29:17 -07:00
Huon Wilson
96172048d3 [Sema/CS] Convenience function for adding a Requirement as a constraint. 2017-10-10 20:17:40 -07:00
Pavel Yaskevich
4e7a089717 [ConstraintSolver] Fix handling of defaultable constraint in getPotentialBindings
While trying to find a fixed type for a given type variable, check if
it has representative and if it does, reflect that in the returned type.

Resolves: rdar://problem/34670592
2017-09-29 00:08:07 -07:00
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04: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
Pavel Yaskevich
9d3a8584b4 [ConstraintSolver] NFC: Integrate type-check timeout timer into shrinking phase
To bound the amount of time shrinking is allowed to run, it has to be
integrated with timeout timer allocated for base constraint system.
2017-09-06 19:08:49 -07:00
David Zarzycki
0511edc69f [Sema] NFC: Do one cache lookup instead of three 2017-08-09 17:52:22 -04:00
Slava Pestov
d65ff34a1e Sema: Fix type mixup with unbound method references
When applying a solution containing an unbound reference to
an instance method of a class, the type of the new expression
did not match the type in the constraint system.

Usually this was papered over because CSApply is sprinkled
with coerceToType() calls, but we would crash when passing
an unbound reference to a generic function, or type(of:).
2017-08-01 21:53:06 -07:00
Slava Pestov
db3c74c2a2 Sema: remove unnecessary special case for dynamic method lookup 2017-08-01 21:22:40 -07:00
Slava Pestov
a3cad02708 Sema: Stricter superclass constraints when opening a generic signature
A generic signature like <T : SomeClass> would create
a subtype constraint between the type variable for T and
SomeClass. This is too loose, because a subclass existential
like 'SomeClass & SomeProto' is a subtype of SomeClass, but
cannot bind to T, because it is not representationally a
single retainable pointer.

Fixes <rdar://problem/32617814>, <https://bugs.swift.org/browse/SR-5142>.
2017-07-24 22:58:04 -07:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -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
Slava Pestov
83684eb08a Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration;
we can remove one. Soon, it will change to store a base
declaration context, instead.
2017-07-18 22:09:19 -07:00
Mark Lacey
e83131da30 Assert if we attempt to bind a type involving ErrorType. 2017-07-13 13:22:44 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Mark Lacey
e51e3e4bd4 Update determination of "too complex" expression to take time into account.
By default, end expression type checking after the elapsed process time
is more than 60 seconds for the current expression. This threshold can
be overridden by using -solver-expression-time-threshold=<seconds>.

Resolves rdar://problem/32859654
2017-06-21 16:26:34 -07:00
Mark Lacey
05e79e6b02 Refactor how the expression type checker timer is set up.
Preparation for adding the ability for the expression type checker to be
halted after a period of time.
2017-06-21 14:18:25 -07:00
Pavel Yaskevich
3781877b93 [ConstraintSystem] Track conformance checking done while solving to validate solution
Track outcomes of `conformsToProtocol` calls in `simplifyConformanceConstraints`
to be able to validate conformances when solution is formed to avoid returning
solutions with nominal types with invalid conformances to protocols.
2017-06-15 14:18:36 -07:00
Slava Pestov
443ba236fc Sema: Fix a few problems with generic typealiases in protocols
- Unqualified lookup was incorrectly checking generic arguments even
  when resolving interface types, resulting in a bogus 'Self does
  not conform to P' error when referencing a generic typealias from
  inside a protocol.

- The generic argument check was also done incorrectly if the
  underlying type did not contain any type parameters, resulting
  in bogus ErrorTypes. Just remove the no-type-parameter
  "optimization" instead, since it was working around another
  crash.

- When opening up a generic typealias in the constraint solver, we
  did the wrong thing if the generic typealias was defined in a
  protocol, producing concrete substitutions for the parent type
  instead of a 'Self := ParentType' substitution.

Fixes <rdar://problem/32633645>.
2017-06-07 18:33:46 -07:00
Mark Lacey
ea4e3e58f9 Merge pull request #10147 from rudkx/fix-rdar32570734
[Constraint solver] Do not allow unavailable decls to be favored.
2017-06-06 15:11:06 -07:00
Mark Lacey
65e338ea4a [Constraint solver] Do not allow unavailable decls to be favored.
There is a short-circuiting hack in the constraint solver that speeds up
solving, but isn't generally sound. If we allow unavailable decls to be
considered "favored", this can fire and result in our choosing a
solution that involves the unavailable decl where other solutions exist.

Fixes rdar://problem/32570734.
2017-06-06 13:38:36 -07:00
Slava Pestov
56b61ba758 Sema: Don't build ErrorTypes in simplifyType()
Instead, just build a new dependent member type with the
simplified base type.
2017-06-06 00:35:13 -07:00
Slava Pestov
6526d513c0 Sema: Remove the 'extraFunctionAttrs' hack 2017-05-31 17:31:37 -07:00
Slava Pestov
586dda2eb3 Sema: Replace TVO_MustBeMaterializable with TVO_CanBindToInOut
The old TVO_MustBeMaterializable is now equivalent to
!TVO_CanBindToLValue && !TVO_CanBindToInOut.

I tried to update all usages of createTypeVariable() to
pass TVO_CanBindToInOut unless they explicitly passed
TVO_MustBeMaterializable before.

However, in reality TVO_CanBindToInOut is the rare case;
we can remove this flag gradually over time to fix
crashes and diagnostics.
2017-05-26 21:08:08 -07:00
Pavel Yaskevich
5523ca7b9f [ConstraintSystem] Strip labels from enum elements when passed as values
Enum elements have to be treated the same way as regular functions
when passed as values, which means labels have to be stripped from
their argument types.

Resolves: rdar://problem/32300339.
2017-05-26 15:32:48 -07:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
73976b2134 Sema: Remove TypeChecker::getTypeOfRValue() 2017-05-24 01:56:21 -07:00
Slava Pestov
2b86bed47e Sema: Clean up subscript handling in getTypeOfMemberReference()
We did things with subscripts in two places in this function;
move them closer together.
2017-05-24 01:49:45 -07:00
Slava Pestov
e0ea83a157 Sema: Move handling of subscripts from getUnopenedTypeOfReference() to getTypeOfMemberReference() 2017-05-24 01:38:11 -07:00
Slava Pestov
a75438a707 Sema: Move TypeChecker::getUnopenedTypeOfReference() to ConstraintSystem.cpp 2017-05-24 01:28:15 -07:00
Slava Pestov
b112e95a7c Sema: Clean up ConstraintSystem::getTypeOfReference()
Separate out the code paths for different kinds of Decls
to make the logic here more apparent.
2017-05-24 00:20:55 -07:00