Commit Graph

335 Commits

Author SHA1 Message Date
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
Slava Pestov
c23686f5c0 Sema: Better handling of type members in getTypeOfMemberReference()
We don't actually want to open the type; instead, calculate the
substituted member type using substMemberTypeWithBase(), which
will return an unbound generic type if the member is a generic
nominal or type alias, and then it open it with openUnboundGenericType().

This is NFC for now, but I need generic typealiases to come in as
UnboundGenericTypes here in a subsequent patch.
2017-05-24 00:20:45 -07:00
Slava Pestov
fe41900873 Sema: Split off ConstraintSystem::openUnboundGenericType() from openType()
The openType() function did two things:

- Replace unbound generic types like 'G' with fresh type variables
  applied to bound generic types, like 'G<$T0>'.

- Replace generic parameters with type variables from the replacement
  map.

The two behaviors were mutually exclusive and never used from the
same call site, so split them up into two independent functions.

Also, eliminate ConstraintSystem::openBindingType() since it was only
used in one place and could be expressed in terms of existing functions.
2017-05-23 02:10:03 -07:00
Slava Pestov
a6dfcd52cf Sema: Remove OverloadChoiceKind::TypeDecl, which was never used 2017-05-23 02:10:02 -07:00
Slava Pestov
ca6e4e6138 Sema: Clean up openGeneric() for nested generic types
If we had an unbound generic type whose parent was a bound
generic type, and the outer type's generic signature
placed generic constraints on outer parameters, we would
create type variables that weren't ever bound to anything.

Previously, this would never come up, but it will once
preCheckExpression() is folding more MemberRefExprs down
to TypeExprs.
2017-05-21 18:11:52 -07:00
Joe Groff
d16eb33477 Sema: Bind context generic params using the current ConstraintSystem's generic environment instead of the decl's DC.
Fixes SR-4833.
2017-05-19 10:47:57 -07:00
Slava Pestov
03ebba50be Sema: Fix lvalue access of class existential payloads
Now that SILGen can correctly lower lvalue accesses of
class existential payloads, remove a hack in Sema that
was simply doing the wrong thing.

Fixes <rdar://problem/31858378>.
2017-05-15 20:14:48 -07:00
Slava Pestov
6c443113ae Sema: Generic parameters can only bind to materializable types
I don't have a test case for this, so it might be a no-op.
But it's clearly "correct".
2017-05-10 22:01:15 -07:00
Graydon Hoare
b5292f04f8 Add an assortment of new "always-on" metrics. 2017-04-28 13:56:13 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Slava Pestov
db58e02cb2 Sema: Hook up layout constraints to the solver
There were various problems with layout constraints either
being ignored or handled incorrectly. Now that I've exercised
this support with an upcoming patch, there are some fixes
here.

Also, introduce a new ExistentialLayout::getLayoutConstriant()
which returns a value for existentials which are class-constrained
but don't have a superclass or any class-constrained protocols;
an example would be AnyObject, or AnyObject & P for some
non-class protocol P.

NFC for now, since these layout-constrained existentials cannot
be constructed yet.
2017-04-13 21:17:05 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
4efa9eaa8a Sema: Update getTypeOfMemberReference() for subclass existentials
If the member came from a class, we're not going to substitute
the 'Self' type. Instead, we open the existential, upcast the
archetype up to the class type and access the member as if it
were a class member in the usual way.
2017-04-10 17:05:44 -07:00
Slava Pestov
819dfd5211 Sema: Better type safety for opened types map
Now that we no longer map dependent member types to fresh type
variables, the keys in the replacement map can just be
GenericTypeParamTypes.
2017-04-10 17:04:36 -07:00
Slava Pestov
ed4c681aae Sema: Simplify Solution::computeSubstitutions()
Don't pass in the opened type; instead have the caller call
simplifyType() if needed. Also, make computeSubstitutions()
bail out if there's no generic signature, which allowed
unifying several generic vs non-generic code paths.

Hopefully there is enough short circuiting in there now that
we're not doing any extra work in the non-generic case.
2017-04-10 17:04:36 -07:00