Commit Graph

7976 Commits

Author SHA1 Message Date
Mark Lacey
03e2040891 [Constraint system] Remove redundant duplicates of favored constraints.
When creating disjunctions with favored constraints in constraint
optimization, we actually ended up duplicating the constraint that we
favor, resulting with extra constraints in the disjunction.

Noticed while debugging other issues.
2017-04-12 16:01:19 -07:00
Mark Lacey
024338a1e5 Merge pull request #8725 from rudkx/propagate-constraints
[Constraint system] More or less rewrite the constraint propagation p…
2017-04-12 14:46:50 -07:00
John McCall
f733e761f4 Merge pull request #8724 from rjmccall/fix-value-type-recursion
Fix the type-checker's recursive value type checking.
2017-04-12 17:13:08 -04:00
John McCall
b233e872dc Fix the type-checker's recursive value type checking.
Track the types we've seen instead of the type declarations we've
passed through, which eliminates some holes relating to generic types.
Detect infinite expansions by imposing an arbitrary limit.

Fixes rdar://30355804
2017-04-12 15:55:45 -04:00
Slava Pestov
374db66e8b Merge pull request #8685 from slavapestov/subclass-existentials-silgen
Preliminary SILGen support for subclass existentials (SE-0156)
2017-04-12 11:44:23 -07:00
Mark Lacey
337684cb4d [Constraint system] More or less rewrite the constraint propagation pass.
This is still disabled by default, and as with the previous
implementation does not pass all tests if enabled.

Rather than looking for applicable function constraints and then looking
at the bind overload disjunctions associated with those, instead
directly collect all bind overload disjunctions and revise the enabled
elements of those disjunctions by attempting to bind them simultaneously
with the elements of other disjunctions that are linked to this one
through applicable function constraints.
2017-04-12 11:22:52 -07:00
Arnold Schwaighofer
69e6f07167 Merge pull request #8701 from aschwaighofer/wip_ast_silgen_const_string_literal
AST/SILGen support for constant string literals
2017-04-12 09:52:18 -07:00
practicalswift
7684e73388 Merge pull request #8706 from practicalswift/excess-logic
[gardening] Remove redundant logic
2017-04-12 09:51:49 +02:00
Slava Pestov
b756f76a66 Sema: Update 'can be represented in @objc' logic for subclass existentials 2017-04-12 00:07:30 -07:00
Slava Pestov
3720badc2a Sema: Fix matchTypes() for existential to superclass conversions
Now that mayHaveSuperclass() is back to its old meaning, we can't
piggy-back off of it anymore and must add a new bit of logic
for class-constrained existential to superclass conversions.

Also re-organize the code a bit.
2017-04-12 00:07:28 -07:00
Slava Pestov
e2d81a11cb Sema: Fix bug in buildMemberRef() with subclass existentials
Make sure we use the right 'self' type in various places. When
calling a Self-returning class method on a subclass existential,
the following has to happen correctly:

- The existential is opened to produce an archetype with a superclass
  constraint.

- The archetype is upcast to a class type to produce the 'self'
  parameter for the call.

- The method call returns a value with the same type as the 'self'
  parameter.

- The return value is downcast to the opened archetype.

- The opened archetype is converted back to an existential.

Some SILGen tests in an upcoming patch exercise this code path.
2017-04-12 00:07:27 -07:00
Mark Lacey
9bd79299f3 Merge pull request #8699 from rudkx/appease-the-warning-gods
Fix unused variable warnings in release build.
2017-04-11 23:40:21 -07:00
Doug Gregor
5dadfa8fac Merge pull request #8707 from DougGregor/gsb-delayed-reqs
[GSB] Basic infrastructure for delaying and reprocessing requirements
2017-04-11 23:28:27 -07:00
Slava Pestov
9bf22d3b01 Merge pull request #8709 from slavapestov/misc-junk
Fix a bug found by inspection and add some regression tests
2017-04-11 18:14:13 -07:00
Robert Widmann
5b3c4b6844 [NFC] Use the presence of an argument type to check for associated values (#8679)
* Use the presence of an argument type to check for associated values

hasOnlyCasesWithoutAssociatedValues returns true for any serialized
enum declaration whether or not it has cases.  This never really came
up because it's mostly relevant to Sema's proto-deriving mechanism.  Fix
this by using the presence of the case's argument type instead.

* Separate checks for presence of cases and enum simplicity

Necessary because the old behavior was an artifact of the
implementation.
2017-04-11 20:13:17 -04:00
Slava Pestov
2281ff0c1c Sema: Fix another crash with tuple to Any conversion
An earlier patch fixed the case where some tuple elements
were lvalue types. However this only looked into tuples
nested one level deep, when a more correct fix checks the
lvalue recursive property of the type.
2017-04-11 14:26:11 -07:00
Doug Gregor
10ebdcd50a [GSB] Broaden the Boolean result of "add a constraint" operations.
Rather than true (an error occurred) or false (the constraint was
resolved), introduce ConstraintResult to better model what
happened. NFC for now, but the intent here is to report unresolved
constraints through this mechanism.
2017-04-11 14:15:45 -07:00
practicalswift
5e255e07d7 [gardening] Remove redundant logic 2017-04-11 23:04:55 +02:00
Huon Wilson
2bfe7f6c88 [Sema] No release-mode warning in ProtocolRequirementTypeResolver. 2017-04-11 12:44:52 -07:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Mark Lacey
e1d727d76d Fix unused variable warnings in release build. 2017-04-11 10:37:51 -07:00
Slava Pestov
960eed37ef Sema: Remove debug message 2017-04-10 18:00:19 -07:00
Slava Pestov
de323b5bef Sema: Update resolveType() for subclass existentials
If the -enable-experimental-subclass-existentials staging flag
is on, resolveType() now allows protocol compositions to contain
class types. It also diagnoses if a composition has more than one
superclass requirement.

Also, change diagnostics that talked about 'protocol composition'
to 'protocol-constrained type'.

Since such types can now contain a superclass constraint, it's not
correct to call them protocol composition.

"Protocol-constrained type" isn't quite accurate either because
'Any' has no protocols, and 'AnyObject' will have no protocols but
a general class constraint; but those are edge cases which won't
come up in these diagnostics.
2017-04-10 17:11:07 -07:00
Slava Pestov
1b2252f367 Sema: Update TypeChecker::checkInheritanceClause() for subclass existentials 2017-04-10 17:05:46 -07:00
Slava Pestov
2e5b3b6dfc Sema: Update constraint solver for subclass existentials 2017-04-10 17:05:45 -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
473faf1eed AST: Update TypeBase::getSuperclassForDecl() for subclass existentials
This function takes a member of a class and a base type, and returns
the correct 'self' type to substitute into the member's type.

When accessing a member of a subclass existential, if the member
was found via the superclass constraint, we have to erase the
existential down to the class type to calculate the member's
substituted type.

We already had special logic to handle class-constrained archetypes
in the callers of getSuperclassForDecl(); move this check into the
method, and add a similar check for subclass existentials, which
now support the getSuperclass() method.
2017-04-10 17:05:43 -07:00
Slava Pestov
9c3b514c7e AST: New getExistentialLayout() method on TypeBase and CanType
This consolidates calculations which need to look at every
protocol in an existential type. Soon we will also have to
deal with superclass constrained existentials, so start
updating call sites that look at all protocols to use the
new ExistentialLayout and correctly handle a class constraint
as well.

Also, eventually I will kill off the AnyObject protocol and
model it as a protocol composition with no protocols or
superclass, but the requiresClass() flag set.

This is not quite modeled this way yet and AnyObject still
exists, but the new abstraction is a step in the right
direction.
2017-04-10 17:04:37 -07:00
Slava Pestov
54883e82e4 Sema: Fix type lookup from protocol extensions with a class-constrained 'Self'
A protocol extension can add additional generic constraints on
'Self' or associated types thereof. In particular, 'Self' itself
can have a superclass constraint placed on it.

There were a couple of problems with this corner case:

- Type aliases defined in protocols that 'Self' conforms to _as a
  concrete type_ to were not handled properly, triggering an assertion.

  For example,

  protocol P { typealias T = ... }
  class C : P {}
  protocol Q {}

  extension Q where Self : C { ... T ... }

  The conformance o P comes from the 'Self : C' constraint.

- If the type was found in a superclass of 'Self', we used the wrong
  base type for the substitution.

  For example,

  protocol P {}
  class C<T> { typealias A = T }
  class D : C<Int> {}

  extension P where Self : D { ... A ... }

  The substituted type of 'A' should be computed with a self type
  of C<Int> here.

Also, take another stab at cleaning up the mess that is
resolveTypeInContext() and related bits of code.
2017-04-10 17:04:37 -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
Slava Pestov
011fb8117a Sema: Fix a compiler crasher 2017-04-10 17:04:35 -07:00
Joe Groff
7eebb27153 Sema: Infer the specific type of a key path literal from the mutability of the resolved components. 2017-04-10 16:06:40 -07:00
Mark Lacey
8465cf36df [Constraint system] Fix debug output for constraint dumping.
I updated this incorrectly to test the disabled bit on the disjunction
rather than the members.
2017-04-09 16:48:02 -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
Michael Gottesman
6578661521 [gardening] Cleanup control flow in computeCallLevel to reduce indentation level. 2017-04-08 17:37:37 -07:00
Michael Gottesman
5c14ec1e8e [gardening] Refactor out computation of a callee's level into its own helper function.
ExprRewriter::coerceCallArguments is a huge function that is difficult to reason
about. This just moves an obvious subroutine into a real subroutine.
2017-04-08 17:37:37 -07:00
Doug Gregor
c522bb5239 [GSB] Separate out "unresolved" and "direct" type requirement handling.
As we've done with layout requirements, introduce a new entry point
(addTypeRequirement) that handles unresolved type requirements of the
form `T: U`, resolves the types, and then can

1. Diagnose any immediate problems with the types,
2. Delay the type requirement if one of the types cannot be resolved,
or
3. Break it into one or more "direct" requirements.

This allows us to clean up and centralize a bunch of checking that was
scattered/duplicated across the GSB and type checker.
2017-04-07 16:53:11 -07:00
Joe Groff
85ad6b355e Merge branch 'master' into keypaths 2017-04-06 18:02:07 -07:00
Mark Lacey
3c43909686 Merge pull request #8599 from rudkx/propagate-constraints
[Constraint system] Fix some issues with constraint propagation.
2017-04-06 17:33:17 -07:00
Mark Lacey
88123195c9 [Constraint system] Fix some issues with constraint propagation.
There are a handful of things, but the primary ones are that we really
don't want to track depth of recursion so much as whether we are
processing at the "top level" of constraints we're looking at or not so
that we can determine whether we can disable elements from a
disjunction.

Related, there are places where we can bail out earlier if we know
that *any* neighboring constraint passes.

Also updating the way we gather neighboring constraints to be
independent of the function that simplifies them. The original code was
wrong in that in bailed as soon as one of the simplifications
failed (which meant we might not gather all of them).
2017-04-06 15:38:47 -07:00
Mark Lacey
96b01c48b3 Merge pull request #8339 from tonisuter/SR-4347
[Sema] [SR-4347] Improve inference of optional supertypes
2017-04-06 09:02:22 -07:00
swift-ci
9ceb9d5ec9 Merge pull request #8571 from DougGregor/where-clause-validation 2017-04-05 14:26:58 -07:00
Doug Gregor
b2bc5574eb [Type checker] Same-named associated types are not ambiguous within a protocol. 2017-04-05 14:06:14 -07:00
Doug Gregor
44c2f849d6 [Type checker] Continue validating requirements after an error.
We want to validate both type in same-type or conformance constraints,
even when the first type is ill-formed, so we don't leave null types
around for later phases to crash on.

Fixes rdar://problem/31093854.
2017-04-05 14:05:59 -07:00
swift-ci
aa880a190d Merge pull request #8557 from DougGregor/substitution-map-cleanups 2017-04-05 12:04:07 -07:00
Doug Gregor
6878538ba1 [AST] Remove GenericEnvironment from SubstitutionMap; it's unnecessary. 2017-04-05 11:21:39 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Roman Levenstein
96bb989056 Remove a useless line that was left after re-factoring. NFC. 2017-04-05 11:04:46 -07:00