Commit Graph

753 Commits

Author SHA1 Message Date
Slava Pestov
c0d981ad61 GSB: Simplify maybeResolveEquivalenceClass()
When passing in wantExactPotentialArchetype=false, we don't actually ever
call getDependentType() on the result. So the Type + EquivalenceClass form
of ResolvedType can be removed.
2020-07-16 23:31:34 -04:00
Anthony Latsis
28531141d2 AssociatedTypeInference: Self is a valid fixed type witness 2020-07-15 22:34:24 +03:00
Slava Pestov
71e267d5b1 GSB: Teach 'derived via concrete' computation about superclass constraints
Under certain circumstances, introducing a concrete same-type or
superclass constraint can re-introduce conformance constraints
which were previously redundant.

For example, consider this code, which we correctly support today:

protocol P {
  associatedtype T : Q
}

protocol Q {}

class SomeClass<U : Q> {}

struct Outer<T> where T : P {
  func inner<U>(_: U) where T == SomeClass<U>, U : Q {}
}

The constraint 'T == SomeClass<U>' makes the outer constraint
`T : P' redundant, because SomeClass already conforms to P.
It also introduces an implied same-type constraint 'U == T.T'.

However, whereas 'T : P' together with 'U == T.T' make 'U : Q'
redundant, the introduction of the constraint 'T == SomeClass<U>'
removes 'T : P', so we re-introduce an explicit constraint 'U : Q'
in order to get a valid generic signature.

This code path did the right thing for constraints derived via
concrete same-type constraints, but it did not handle superclass
constraints.

As a result, this case was broken:

struct Outer<T> where T : P {
  func inner<U>(_: U) where T : SomeClass<U>, U : Q {}
}

This is the same example as above, except T is related via a
superclass constraint to SomeClass<U>, instead of via a concrete
same-type constraint.

The subtlety here is that we must check if the superclass type
actually conforms to the requirement source's protocol, because it
is possible to have a superclass-constrained generic parameter
where some conformances are abstract. Eg, if SomeClass did not
conform to another protocol P2, we could write

func foo<T, U>(_: T, _: U) where T : SomeClass<U>, T : P2 {}

In this case, 'T : P2' is an abstract conformance on the type 'T'.

The common case where this would come up in real code is when you
have a class that conforms to a protocol with an associated type,
and one of the protocol requirements was fulfilled by a default in
a protocol extension, eg:

protocol P {
  associatedtype T : Q

  func foo()
}

extension P {
  func foo() {}
}

class ConformsWithDefault<T : Q> : P {}

The above used to crash; now it will type-check correctly.

Fixes <rdar://problem/44736411>, <https://bugs.swift.org/browse/SR-8814>..
2020-06-21 23:42:10 -04:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04:00
Slava Pestov
514a0423b6 GSB: Concretize nested types when adding a superclass constraint
When adding a superclass constraint, we need to find any nested
types belonging to protocols that the superclass conforms to,
and introduce implicit same-type constraints between each nested
type and the corresponding type witness in the superclass's
conformance to that protocol.

Fixes <rdar://problem/39481178>, <https://bugs.swift.org/browse/SR-11232>.
2020-05-15 21:58:58 -04:00
Arnold Schwaighofer
5c4bbf3de9 Merge pull request #31736 from aschwaighofer/fix_protocol_conformance_subst
Existentials don't always conform to a protocol via an abstract confo…
2020-05-13 11:27:25 -07:00
Anthony Latsis
df9103e9d7 [NFC] AST: Const-qualify GenericSignatureImpl 2020-05-13 01:03:08 +03:00
Arnold Schwaighofer
b40b1be41d Existentials don't always conform to a protocol via an abstract conformance
So it is not always correct to use the current conformance when substituting.

rdar://62894495
2020-05-12 12:20:01 -07:00
Anthony Latsis
724c76041d Merge pull request #31555 from AnthonyLatsis/arch-resolution-kind
GSB: Propagate ArchetypeResolutionKind to resolveDependentMemberTypes
2020-05-07 04:24:24 +03:00
Anthony Latsis
dfcc656501 GSB: Propagate ArchetypeResolutionKind to resolveDependentMemberTypes when resolving equivalence classes 2020-05-06 23:43:53 +03:00
Anthony Latsis
bc49a8e232 [Diags] NFC: Audit diags using DeclName for names of nominals and vars 2020-05-02 16:08:24 +03:00
Varun Gandhi
65577940d0 [NFC] Get rid of -Wrange-loop-analysis warnings. (#31324) 2020-04-27 09:47:52 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Slava Pestov
8d2a4105b4 GenericSignatureBuilder: Improved counters 2020-04-21 23:27:05 -04:00
Slava Pestov
b3aea6ee38 GenericSignatureBuilder: Simplify RequirementRHS type 2020-04-21 23:26:39 -04:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
swift-ci
9a0efcac2a Merge pull request #30548 from AnthonyLatsis/sr-7855 2020-04-13 13:20:27 -07:00
Robert Widmann
1f904ca86d Merge pull request #30669 from CodaFi/consteval
[NFC] A Handful of Sweeping Evaluator Cleanups
2020-03-27 09:43:28 -07:00
marcrasi
eae4c5eece [AutoDiff upstream] @differentiable function type sema (#30648)
Add type checking for `@differentiable` function types:
- Check that parameters and results conform to `Differentiable`.
- Implicitly conform parameters and results whose types are generic parameters
  to `Differentiable`.
- Upstream most of the differentiable_func_type_type_checking.swift test from
  `tensorflow` branch. A few function conversion tests have not been added
   because they depend on the `@differentiable` function conversion pipeline.

Diagnose gracefully when the `Differentiable` protocol is unavailable because
`_Differentiation` has not been imported.

Resolves TF-823 and TF-1219.
2020-03-26 23:28:02 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Slava Pestov
53ab30044c GSB: Fix maybeResolveEquivalenceClass() with member type of concrete type
Fixes <rdar://problem/55401811>, <https://bugs.swift.org/browse/SR-11475>.
2020-03-25 16:53:57 -04:00
Anthony Latsis
a826da5979 [Sema] Fixits for assoc. type restatement hints should account for where clauses 2020-03-21 05:31:37 +03:00
swift-ci
cbcc377259 Merge pull request #30453 from gribozavr/simplify-append 2020-03-17 13:18:43 -07:00
Dmitri Gribenko
b2164f238a Simplified SmallString::append calls 2020-03-17 19:33:42 +01:00
Dmitri Gribenko
80e4a705fe Call placement new directly on the allocator
... avoiding handling a pointer to raw memory.
2020-03-17 19:24:09 +01:00
fischertony
6f08216936 Sema: Support where clauses on contextually generic decls 2020-03-05 04:37:12 +03:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Suyash Srijan
c435646825 [GSB] Delay mapping an invalid subject type to an error type (#29813) 2020-02-18 07:35:42 +00:00
swift-ci
dd4488eb2d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-28 13:04:30 -08:00
Robert Widmann
88d6559722 [GSB] Map invalid subject types in requirement constraints to ErrorType
Resolves SR-12072 and rdar://58941114
2020-01-28 10:15:43 -08:00
swift-ci
dcb4ee0582 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-12 12:23:31 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Arnold Schwaighofer
43c24be5cd Merge remote-tracking branch 'upstream/master' into master-next 2020-01-08 06:41:34 -08:00
Varun Gandhi
022314a640 Merge pull request #28643 from kitaisreal/using-located-instead-of-pair
[Compiler]: Using Located<T> instead of std::pair<SourceLoc, T>
2020-01-06 14:22:29 -08:00
swift_jenkins
81c0ed297a Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 10:19:08 -08:00
Saleem Abdulrasool
e133b20718 GSB: inline some trivial methods
This inlines the comparators since GCC 7 objects to the definition
(which is probably due to scoping).  However, these methods are
templates, which must be visible to the consumers, and should therefore
be in the header.  Given the size, it seems reasonable to just inline
them.
2019-12-26 19:46:53 -08:00
Kita, Maksim
ea6a2dc094 SR-11889: Fixed code review issues
1. Updated Located field names with Pascal Case
2. Updated Located constuctor
3. Formatted lines with more than 80 symbols
2019-12-20 17:18:59 +03:00
Kita, Maksim
c1444dea18 SR-11889: Fixed code review issues 2019-12-20 17:18:59 +03:00
swift_jenkins
6b53fd184c Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 11:00:08 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
swift_jenkins
fe004f5e70 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 20:00:17 -08:00
Robert Widmann
c83c0f4cb7 Filter out invalid nested types from typealias override checking
The lookupDirect means that we can see type declarations nested inside of a protocol. If we do not filter these invalid declarations, we will offer a bogus fixit on top of a cycle diagnostic.  Remove these types from consideration entirely so we don't crash and don't offer bogus fixits.

Resolves rdar://57003317
2019-11-20 15:17:09 -08:00
swift-ci
9f6c8cbf3a Merge remote-tracking branch 'origin/master' into master-next 2019-11-04 12:50:07 -08:00
Robert Widmann
ce4b20c90d [Gardening] Remove dead LazyResolver members 2019-11-04 11:13:14 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00