Commit Graph

7976 Commits

Author SHA1 Message Date
Mark Lacey
c320e6f806 Merge pull request #6213 from rudkx/cs-typemap
Replace Expr::getType() with ConstraintSystem::getType().
2016-12-11 18:34:52 -07:00
Mark Lacey
0a8678cf19 Replace Expr::getType() with ConstraintSystem::getType().
Update CSGen/CSApply/CSSolver to primarily use getType() from
ConstraintSystem.

Currently getType() just returns the type on the expression. As with
setType(), which continues to set the type on the expression, this
will be updated once all the other changes are in place.

This change also moves coerceToRValue from TypeChecker to
CosntraintSystem so that it can access the expression type map in the
constraint system.
2016-12-11 17:46:34 -07:00
Mark Lacey
140df6b312 Merge pull request #6212 from rudkx/reapply
Re-apply: Cache types in the constraint system expression type map.
2016-12-11 15:27:33 -07:00
Mark Lacey
294f90a68b Re-apply: Cache types in the constraint system expression type map.
I've been unable to reproduce the issue that hit on the builder, and
still expect this change to be NFC, so trying it out again. If it
fails, I'll revert again and try another shot at reproducing.

Original commit message:

We create new expressions that have the type on the expression
set. Make sure we capture these types in the constraint system type
map so that we can refer to types uniformally by consulting the map.

NFC.

(cherry picked from commit 57d5d974ff)
2016-12-11 14:07:46 -07:00
swift-ci
fe4bac5b8a Merge pull request #6187 from xedin/SR-3248 2016-12-11 08:33:39 -08:00
Mark Lacey
6abcc32103 Revert "Cache types in the constraint system expression type map." 2016-12-11 00:38:10 -07:00
Mark Lacey
d6f9402833 Merge pull request #6203 from rudkx/cs-typemap
Cache types in the constraint system expression type map.
2016-12-10 23:52:07 -07:00
Mark Lacey
57d5d974ff Cache types in the constraint system expression type map.
We create new expressions that have the type on the expression
set. Make sure we capture these types in the constraint system type
map so that we can refer to types uniformally by consulting the map.

NFC.
2016-12-10 23:12:36 -07:00
Mark Lacey
3fcac9b47b Merge pull request #6198 from rudkx/cs-typemap
Set types in the constraint system type map in CSApply.
2016-12-10 20:21:34 -07:00
Mark Lacey
e00756cda4 Set types in the constraint system type map in CSApply.
The setType() function in ConstraintSystem still sets the types on the
expressions themselves and that will continue until everything is
moved over to using the map.

Unfortunately this exposed cases where we are currently setting the
type multiple times to different values, so I've commented out the
assert that I previously added. I will circle back and start looking
into those issues once everything is moved over.

NFC for now.
2016-12-10 19:25:43 -07:00
Pavel Yaskevich
37c6bdd657 [Diagnostics] Improve diagnostics involving implicitly unwrapped optional functions
In FailureDiagnosis::visitApplyExpr and CalleeCandidateInfo try to look
through ImplicitlyUnwrappedOptional function type, which improves diagnostics
for calls with invalid arguments.

Resolves: SR-3248.
2016-12-09 23:21:24 -08:00
Slava Pestov
ddd19c6207 Sema: Hacky fix for infinite recursion if a class inherits from itself
This seems to come up a lot; we need to consolidate and clean up
inheritance circularity breaks.
2016-12-09 20:12:29 -08:00
Slava Pestov
4c0d1488e2 Sema: Don't add implicit constructors when checking inheritance clause
This leads to some bad recursion through validateDecl(), even
when called from the ITC. We already had machinery to add
implicit constructors later, it just had to be extended to
do it for the superclass as well.
2016-12-09 20:12:28 -08:00
Mark Lacey
a61a56aa27 Merge pull request #6183 from rudkx/cs-typemap
Update constraint generation to set types in the constraint system's …
2016-12-09 19:36:04 -07:00
Slava Pestov
e063e8297c Sema: Some fixes for the ITC
- In functions called from resolveType(), consistently
  use a Type() return value to indicate 'unsatisfied
  dependency', and ErrorType to indicate failure.

- Plumb the unsatisfiedDependency callback through the
  resolution of the arguments of BoundGenericTypes, and
  also pass down the options.

- Before doing a conformance check on the argument of a
  BoundGenericType, kick off a TypeCheckSuperclass request
  if the type in question is a class. This ensures we don't
  recurse through NominalTypeDecl::prepareConformanceTable(),
  which wants to see a class with a valid superclass.

- The ResolveTypeOfDecl request was assuming that
  the request was satisfied after calling validateDecl().
  This is not the case when the ITC is invoked from a
  recursive call to validateDecl(), hack this up by returning
  *true* from isResolveTypeDeclSatisfied(); otherwise we
  assert in satisfy(), and we can't make forward progress
  in this case anyway.

- Fix a bug in cycle breaking; it seems if we don't invoke
  the cycle break callback on all pending requests, we end
  up looping forever in an outer call to satisfy().

- Remove unused TR_GlobalTypeAlias option.
2016-12-09 17:36:49 -08:00
Mark Lacey
1f6b5ca3d3 Update constraint generation to set types in the constraint system's expression type map. 2016-12-09 16:21:32 -07:00
Mark Lacey
5304d0da10 Merge pull request #6168 from rudkx/cs-typemap
Add a map from expressions to types in the constraint system.
2016-12-09 15:29:40 -07:00
Mark Lacey
3d9e4d7f86 Add a map from expressions to types in the constraint system.
This map will be used instead of directly accessing types on
expressions. This will allow us to avoid mutating the types on
expression trees directly, making it possible to remove code that
currently attempts to save & restore types, and reducing the number of
bugs that exist as a result of not always perfectly saving & restoring
types (e.g. dangling references to released type variables).

The setType() function introduced here currently still sets the type
on the expression, so this change is NFC. This is just step one of
staging in this transition to using the types from the maps.

A map for TypeLocs and possibly other maps for other types we mutate
will be added in future commits.
2016-12-09 12:07:09 -07:00
Slava Pestov
58d4a07fa6 Sema: Clean up accessor synthesis
- Remove unnecessary calls to validateDecl() and typeCheckDecl()
- Simplify the logic around synthesizing materializeForSet
2016-12-08 23:22:16 -08:00
Slava Pestov
1bebd8f917 Sema: Clean up getTypeOfRValue() a bit 2016-12-08 23:20:09 -08:00
Slava Pestov
9833ab0ec2 Sema: Set the outer parameter list in validateGenericTypeSignature() 2016-12-08 23:20:08 -08:00
Slava Pestov
e4258f82e2 Sema: Remove recently-added workaround now that SubstitutedType is gone 2016-12-08 23:20:08 -08:00
practicalswift
a7ae48481d [gardening] Remove never-read bool anythingShuffled. 2016-12-08 13:36:10 +01:00
practicalswift
14c4f3c46f [gardening] Remove never-read bool anyRemoved. 2016-12-08 13:36:09 +01:00
practicalswift
7fba953464 [gardening] Remove never-read bool recovered. 2016-12-08 13:36:01 +01:00
Pavel Yaskevich
f1be35c178 [QoI] Add return after coercing to TupleElementExpr in ExprRewriter::coerceToType
Adds missing return statement for coercions which extract a single
element from a tuple aka tuple-to-scalar conversions in ExprRewriter::coerceToType.
2016-12-08 02:05:46 -08:00
Doug Gregor
c250acf8d9 [AST] Record the "owning" declaration context of generic environments.
While not strictly needed for type checking, it's extremely useful for
debugging and verification to know what context a particular generic
environment is associated with. This information was in a kludgy side
table, but it's worth a pointer in GenericEnvironment to always have
it available.
2016-12-07 21:35:53 -08:00
Slava Pestov
198c13501c Merge pull request #6069 from slavapestov/remove-substituted-type
Remove SubstitutedType
2016-12-07 16:14:55 -08:00
Doug Gregor
00a7981e05 [Type checker] Eliminate one "pass" in generic environment validation.
We no longer need a separate "pass" that creates an archetype builder
that inherits context archetypes, because we no longer ever inherit
context archetypes.
2016-12-07 14:27:49 -08:00
Doug Gregor
ea067c0346 [AST] Eliminate ArchetypeType::NestedType.
Now that we no longer distinguish outer archetypes from inner
archetypes, we can replace NestedType with just Type.
2016-12-07 14:27:49 -08:00
Slava Pestov
ed75fdacab Sema: Fix for accidental desugaring in simplifyType()
When called with a ParenType wrapping a DependentMemberType,
we would drop the ParenType because we used type->getAs<ParenType>()
rather than dyn_cast<ParenType>(type.getPointer()).

This fixes an existing QoI issue with closure argument tuples,
and prevents another regression once SubstitutedType is removed.
2016-12-07 14:16:43 -08:00
Doug Gregor
e882d05137 Eliminate the generic environment from ArchetypeBuilder::addGenericSignature()
It's not being used now. NFC
2016-12-07 08:10:12 -08:00
Doug Gregor
b70abdb10d [Type checker] Don't allow us to resolve bogus types from outside protocol scope.
This is a hack to avoid crashing on invalid code where a protocol is
nested inside some other generic context, and one attempts to use a
generic parameter or associated type from the enclosing generic
context. Any attempts to do so will violate the invariant that
protocols are top-level, which now crashes much more readily.

@slava_pestov is working on a far more principled fix for this area.
2016-12-07 08:10:12 -08:00
Doug Gregor
aa3d024f8d [Type checker] Eliminate reuse of contextual archetypes in nested generics.
Prior to this change, nested generics always reused the archetypes of
either enclosing contexts. For example, given:

  struct X<T> {
    func f<U>(_: U) { }
  }

The generic environment for X.f(_:) would use the same archetype for T
as the generic environment X. This reuse allowed some sloppiness
within the implementation---one did not necessarily have to remember
to substitute entities that came from an immediate outer context---but
caused an annoying limitation that nested generics could not add any
constraints to an archetype that came from an outer scope. Worse, the
compiler would not always diagnose this as an error, leading to
constraints being silently dropped, as in the example from the
referenced radar (see the change to
test/Generics/associated_types.swift).

Now, build a fresh generic environment for each context that
introduces new generic parameters, with archetypes that are completely
separate from the archetypes of enclosing contexts.

Fixes rdar://problem/29207581.
2016-12-07 08:10:12 -08:00
Doug Gregor
46a55bd372 [Type checker] Map contextual types of references to decls in outer scopes.
When referring to a declaration from an enclosing scope, make sure to
map the contextual type from its declaring context to the context from
which the declaration is referenced.
2016-12-07 08:10:11 -08:00
Doug Gregor
3ccf0d70eb Use the innermost declaration context when gathering member substitutions. 2016-12-07 08:10:10 -08:00
Doug Gregor
2bb29350b2 [Type checker] Record generic environment of inferred type witnesses. 2016-12-07 08:10:10 -08:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
Ben Langmuir
ef7f8f7c9a Merge pull request #6102 from benlangmuir/fix-032
[code-completion] Allow ErrorType in solution to avoid assertion failure
2016-12-06 12:26:33 -08:00
Ben Langmuir
c01bff7ddb [code-completion] Allow ErrorType in solution to avoid assertion failure
When CSGen encounters an error it may set a type to ErrorType, but the
system will still "solve".
2016-12-06 10:42:16 -08:00
Slava Pestov
dbdb8d62ea Merge pull request #6094 from slavapestov/cleanup-generic-resolver-workaround
Cleanup generic resolver workaround
2016-12-06 10:24:18 -08:00
Slava Pestov
81fad09b8d Sema: Nominal types nested inside protocols are not requirements 2016-12-06 09:41:30 -08:00
Slava Pestov
fdaa886065 Sema: Rework resolveTypeInContext()
Separate the "find the correct context" part from "substitute in the
base type" part. The former can go away completely after a bit of
refactoring.
2016-12-06 09:39:28 -08:00
swift-ci
20c44e6de4 Merge pull request #6095 from akyrtzi/fix-ide-crash-103 2016-12-06 09:06:31 -08:00
Argyrios Kyrtzidis
7a390e1fac [code-completion] Improve robustness of Solution::computeSubstitutions and check if OpenedTypes contains the provided locator.
Fixes validation-test/IDE/crashers/103-swift-constraints-solution-resolvelocatortodecl.swift.
2016-12-06 08:28:53 -08:00
Doug Gregor
553216a11e Address most of Slava's commentary on this PR. 2016-12-05 22:44:51 -08:00
Doug Gregor
9758499353 [Type checker] Teach performTypeLocChecking() to provide a generic environment.
This routine was passing a 'null' generic environment when it should,
in fact, provide the generic environment for its context. Fixes a
code-completion regression introduced by the removal of
PartialGenericTypeToArchetypeResolver.
2016-12-05 22:44:51 -08:00
Doug Gregor
6c7277be2c [Type checker] Work around issues with badly broken generic code.
The GenericTypeOrArchetypeResolver changes are effectively porting
some existing hacks from the now-dead
PartialGenericTypeOrArchetypeResolver, which dodges some regressions
in the compiler-crashers suite and fixes 11 new crashers. There is
undoubtedly a more principled approach to fix these problems, most of
which now step from recursively looking for a generic environment that
isn't there, but doing so requires improvements to our name lookup.
2016-12-05 22:44:24 -08:00
Doug Gregor
13e1714779 Remove PartialGenericTypeToArchetypeResolver. 2016-12-05 22:42:04 -08:00
Doug Gregor
39eeb1343d [Type checker] Eliminate SIL parser's use of PartialGenericTypeToArchetypeResolver. 2016-12-05 22:42:04 -08:00