Commit Graph

520 Commits

Author SHA1 Message Date
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
Slava Pestov
6b4c877b68 Sema: simplifyType() can return early if the type has no variables
This allows calling simplifyType() unconditionally even if we
know we don't have any type variables in the type.
2017-04-10 17:04:36 -07:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00
Xi Ge
75e191f5ac AST: Summarize a commonly used call chain in AbstractFunctionDecl. NFC (#8424) 2017-03-30 10:51:10 -07:00
Joe Groff
eb40d4303b Sema: Add a stdlib-internal _openExistential helper.
Leverage the "special type-checking semantics" hack to pass an opened existential down to an arbitrary subexpression. Please don't use this.
2017-03-10 13:41:00 -08:00
Mark Lacey
b026a07fd8 Add a scale-test counter for expression type checking.
Also add the first example of using the counter to test for
known-exponential typechecking behavior for nil-coalescing.
2017-02-23 12:08:30 -08:00
Slava Pestov
1a8ba93e59 Sema: Refactor getTypeOfMemberReference() for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:12 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07: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
Graydon Hoare
9cb1c52fd8 Count constraint-solving memory more precisely, rdar://29684330 2017-02-06 13:04:19 -08:00
Slava Pestov
cf4043b668 AST: Get rid of old form of Type::subst()
First, add some new utility methods to create SubstitutionMaps:

- GenericSignature::getSubstitutionMap() -- provides a new
  way to directly build a SubstitutionMap. It takes a
  TypeSubstitutionFn and LookupConformanceFn. This is
  equivalent to first calling getSubstitutions() with the two
  functions to create an ArrayRef<Substitution>, followed by
  the old form of getSubstitutionMap() on the result.

- TypeBase::getContextSubstitutionMap() -- replacement for
  getContextSubstitutions(), returning a SubstitutionMap.

- TypeBase::getMemberSubstitutionMap() -- replacement for
  getMemberSubstitutions(), returning a SubstitutionMap.

With these in place, almost all existing uses of subst() taking
a ModuleDecl can now use the new form taking a SubstitutionMap
instead. The few remaining cases are explicitly written to use a
TypeSubstitutionFn and LookupConformanceFn.
2017-02-03 19:55:40 -08:00
Mark Lacey
ecedb337e7 [Sema] In simplifyType, if substitution fails retry with IUOs stripped.
We can end up with IUOs bound as a result of overload resolution. When
this happens and the resulting type is used as a generic, we can end up
with dependent member types that fail to simplify properly as a result
of failing to substitute due to the IUO getting in the way. In these
cases it should be completely safe to strip the IUO off and retry
substitution with the base type.

This isn't really an ideal fix by any means, and we need to revisit how
we handle bindings to make it more uniform, but for now I think this is
a reasonable path to move forward.

Fixes a source compatibility regression.

rdar://problem/29960575
2017-01-31 23:52:29 -08:00
Slava Pestov
5cbaa9d7a6 Sema: When simplifying types, build ErrorTypes for failed conformance lookups 2017-01-28 18:35:23 -08:00
John McCall
39b65f49a0 Track the actual DC of a member access in the constraint system.
Without this, CSGen/CSSimplify and CSApply may have differing
opinions about whether e.g. a let property is settable, which
can lead to invalid ASTs.

Arguably, a better fix would be to remove the dependency on the
exact nested DC.  For example, we could treat lets as settable
in all contexts and then just complain later about invalid
attempts to set them.  Or we could change CSApply to directly
use the information it already has about how an l-value is used,
rather than trying to figure out whether it *might* be getting set.
But somehow, tracking a new piece of information through the
entire constraint system seems to be the more minimal change.

Fixes rdar://29810997.
2017-01-26 00:14:21 -05:00
Slava Pestov
8de0ca54e5 Sema: Merge the two implementations of simplifyType()
ConstraintSystem::simplifyType() replaced types with their fixed types
from the global map.

Solution::simplifyType() replaced types with their fixed types from the
current bindings.

There were some minor differences between the two, and some dead code.
2017-01-19 20:07:06 -08:00
Slava Pestov
a22b46244c Sema: Don't canonicalize base type in member lookup
We would lose ParenType sugar in function types as a result.

Fixes part of <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00