Commit Graph

123 Commits

Author SHA1 Message Date
Hamish Knight
805f25d50c [Sema] Try limit kicking interface type in filterForEnumElement
Kicking the interface type request of the base decl here is wrong
if the decl is e.g a `self` capture in a closure, since we'll be in
the middle of type-checking the closure. I'm planning on properly
fixing this by folding the lookup into the constraint system, but for
now let's at least avoid kicking the request if we don't have an enum
case or enum var. That at least prevents it from affecting cases where
e.g you're pattern matching against a property in a class.

We could potentially tighten up the checking here even further, but
that could potentially impact source compatibility for ambiguous
cases. I'd like to keep this patch low risk, and then deal with any
fallout as part of the pattern type-checking work.

rdar://146952007
2025-04-09 14:56:49 +01:00
Anthony Latsis
43e82b4f7e Sema: Partially revert existential opening fix
Selectively revert 36683a804c to resolve
a source compatibility regression. See inline comment for use case. We
are going to consider acknowledging this use case in the rules in a
future release.
2025-02-14 22:30:28 +00:00
Slava Pestov
5a43d2403e Sema: Simplify opened existential types in solution 2024-09-04 10:42:19 -04:00
Anthony Latsis
d024dc363f Gardening: Migrate test suite to GH issues: validation-test/compiler_crashers_2 2022-09-19 22:33:48 +03:00
Slava Pestov
e6d1ef9f6d Merge pull request #41868 from slavapestov/rqm-opaque-archetypes
RequirementMachine: Opaque archetype support (sort of)
2022-03-17 23:06:24 -04:00
Slava Pestov
2f727d6b47 RequirementMachine: Opaque archetype support (sort of)
Complete support is behind a flag, because it can result in a non-convergent
rewrite system if the opaque result type has a recursive conformance of its
own (eg, `some View` for SwiftUI's View protocol).

Without the flag, it's good enough for simple examples; you just can't have
a requirement that mentions a nested type of a type parameter equated to
the concrete type.

Fixes rdar://problem/88135291, https://bugs.swift.org/browse/SR-15983.
2022-03-17 17:45:59 -04:00
Slava Pestov
f518c80f4b Move validation-test/compiler_crashers_2/sr8968.swift to test/Generics/ since it passes with the Requirement Machine 2022-03-16 23:23:10 -04:00
Robert Widmann
0aead2818c Add a Compiler Crasher
The problem is that we currenly cannot represent the generic signature of
values of type `any P<some P>`. This is because we wind up producing

<Self where Self : P, Self.T == (some P)>

What we'd like to do in the future is erase the errant (some P) with
a fresh generic parameter and keep a substitution map on the side that
records the opaque type constraint. Something like

<Self, Opaque1 where Self : P, Opaque1 : P, Self.T == Opaque1> where Opaque1 == (some P)
2022-03-09 11:49:38 -08:00
Alejandro Alonso
81ba0cee34 Disable unsupported_opened_existential.swift
disable only for asserts

one more time
2022-01-24 17:22:25 -08:00
Holly Borla
b3b24a78cd [Test] Add a compiler crasher test case for unsupported opened existential
types.
2022-01-19 22:53:59 -08:00
Slava Pestov
bcee54b936 GSB: The combination of a superclass and conformance requirement might force a type to be concrete
A protocol can constrain an associated type to Self:

    protocol P {
      associatedtype A : Q where A.B == Self
    }

    protocol Q {
      associatedtype B
    }

And a class might conform to this protocol:

    class C : P {
      typealias A = D
    }

    class D : Q {
      typealias B = C
    }

The generic signature <Self where Self : P, Self : C> is built during
conformance checking. Since Self : C, we must have that Self.A == D;
since D.B == C, the requierement 'A.B == Self' in protocol P implies
that 'Self == C'. So the correct minimized signature here is
<Self where Self == C>.

This wasn't handled properly before, because of assumptions in
removeSelfDerived() and a couple of other places.

Fixes rdar://71677712, rdar://76155506, https://bugs.swift.org/browse/SR-10033,
https://bugs.swift.org/browse/SR-13884.
2021-04-03 23:04:39 -04:00
Slava Pestov
f3f2ea6f62 AST: Skip requirement checks in IsBindableVisitor::visitBoundGenericType() if substituted type is an interface type
IsBindableVisitor is part of TypeBase::substituteBindingsTo(), which
is used for two things:

- Checking if one contextual type is a proper substitution of another
  contextual type, used in the solver

- To compute the substituted generic signature when lowering a SIL
  function type

In the first case, we're interested in knowing if the substitution
succeeds or fails. In the second case, we know the substitution is
correct by construction, and we're trying to recover the generic
requirements.

In the second case though, the substituted type might be an
interface type, and if the interface type is constrained to a
concrete type in the original type's generic signature, we would
conclude that the substitution should fail.

This is incorrect, and we should just skip the check if the
substituted type is an interface type -- we do not have enough
information to know if it succeeds, and instead we must assume it
does because otherwise the substituted type passed in to type
lowering must be incorrect.

Fixes https://bugs.swift.org/browse/SR-13849.
2021-04-01 01:02:38 -04:00
Slava Pestov
504d4f526a Add two passing regression tests and a failing one 2021-03-17 17:25:41 -04:00
Slava Pestov
91ebe4485c GSB: Move signature verification from CanGenericSignature::getCanonical() to computeGenericSignature()
Doing this when computing a canonical signature didn't really
make sense because canonical signatures are not canonicalized
any more strongly _with respect to the builder_; they just
canonicalize their requirement types.

Instead, let's do these checks after creating the signature in
computeGenericSignature().

The old behavior had another undesirable property; since the
canonicalization was done by registerGenericSignatureBuilder(),
we would always build a new GSB from scratch for every
signature we compute.

The new location also means we do these checks for protocol
requirement signatures as well. This flags an existing fixed
crasher where we still emit bogus same-type requirements in
the requirement signature, so I moved this test back into
an unfixed state.
2021-03-11 21:07:33 -05:00
Slava Pestov
f3f9555c55 GSB: New implementation of getConformanceAccessPath()
A new implementation from "first principles". The idea is that
for a given conformance, we either have an explicit source
which forms the root of the requirement path, or a derived
source, which we 'factor' into a parent type/parent protocol
pair, and a requirement signature requirement.

We recursively compute the conformance access path of the
parent type and parent protocol, and append the path element
for the requirement.

This fixes a long-standing crasher, and eliminates two hacks,
the 'usesRequirementSource' flag in RequirementSource, and
the 'HadAnyRedundantConstraints' flag in GenericSignatureBuilder.

Fixes https://bugs.swift.org/browse/SR-7371 / rdar://problem/39239511
2021-02-23 16:26:04 -05:00
Slava Pestov
8edf4264ae GSB: Better handling of unresolved DependentMemberTypes in maybeResolveEquivalenceClass()
A DependentMemberType can either have a bound AssociatedTypeDecl,
or it might be 'unresolved' and only store an identifier.

In maybeResolveEquivalenceClass(), we did not handle the unresolved
case when the base type of the DependentMemberType had itself been
resolved to a concrete type.

Fixes <rdar://problem/71162777>.
2021-02-11 16:33:35 -05:00
Nate Chandler
0113849396 [Test] Disable two tests that hang asan bots.
The following tests are disabled here:

    compiler_crashers_2/0208-sr8751.swift
    compiler_crashers_2/0207-sr7371.swift

rdar://problem/65571199
2020-07-14 16:23:38 -07: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
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
Roopesh Chander
abaf79d198 [Property wrappers] Move sr11637 compiler crasher to fixed directory 2020-04-14 13:49:57 -07:00
Hamish Knight
c667d2b361 Use DefaultArgumentExpr for caller-side defaults
This commit changes how we represent caller-side
default arguments within the AST. Instead of
directly inserting them into the call-site, use
a DefaultArgumentExpr to refer to them indirectly.

The main goal of this change is to make it such
that the expression type-checker no longer cares
about the difference between caller-side and
callee-side default arguments. In particular, it
no longer cares about whether a caller-side
default argument is well-formed when type-checking
an apply. This is important because any
conversions introduced by the default argument
shouldn't affect the score of the resulting
solution.

Instead, caller-side defaults are now lazily
type-checked when we want to emit them in SILGen.
This is done through introducing a request, and
adjusting the logic in SILGen to be more lenient
with ErrorExprs. Caller-side defaults in primary
files are still also currently checked as a part
of the declaration by `checkDefaultArguments`.

Resolves SR-11085.
Resolves rdar://problem/56144412.
2019-11-20 15:07:32 -08:00
Robert Widmann
3f36ecf5ba Add a regression test for a GSB crasher
From rdar://56673657
2019-11-11 10:27:33 -08:00
Suyash Srijan
d311879122 [Test] Move test case to compiler crashers 2019-10-19 03:34:09 +01:00
Slava Pestov
5189daafd3 Add a couple of crashing test cases 2019-09-20 15:08:47 -04:00
Jorge Revuelta Herrero
cec0821220 Compiler crash for SR11108 2019-09-11 13:47:15 +02:00
Suyash Srijan
8c5730abe6 [Test] Fix incorrect SR number 2019-08-31 20:10:19 +01:00
Suyash Srijan
d576fc1b83 [Test] Add a compiler crasher 2019-08-31 20:03:06 +01:00
Arnold Schwaighofer
031dead69c Try to fix failure of this test on noasserts builds of the compiler
This test failed on the oss-swift_tools-R_stdlib-RD_test-simulator bot.

rdar://54707188
2019-08-26 08:19:26 -07:00
Greg Titus
3556fdf557 Sample test in compiler_crashers for sr-11232. 2019-08-24 08:56:06 -07:00
Slava Pestov
e0c29408eb This test only fails when asserts are on 2019-03-06 15:42:14 -05:00
Slava Pestov
c47683cdeb Add failing test case for GSB bug 2019-03-01 21:01:51 -05:00
Greg Titus
c7ae3e6736 Crasher fixed. 2018-10-13 20:13:35 -07:00
Doug Gregor
92d622ab41 [Type checker] Eliminate TypeResolverContext::GenericSignature.
The name-lookup behavior that avoids looking for members of a nominal type
or extension therefore when resolving the inheritance clause is now
handled by UnqualifiedLookup, so remove it from the type checker itself.

Fixes rdar://problem/39130543.
2018-08-14 23:17:57 -07:00
Robert Widmann
0b33a69540 Merge pull request #17195 from brentdax/label-fable
Implicit tuple interpolations, take two
2018-06-18 15:54:30 -07:00
Doug Gregor
ef337bb8ba [Evaluator] Use the request-evaluator for the superclass of a class.
Wire up the request-evaluator with an instance in ASTContext, and
introduce two request kinds: one to retrieve the superclass of a class
declaration, and one to compute the type of an entry in the
inheritance clause.

Teach ClassDecl::getSuperclass() to go through the request-evaluator,
centralizing the logic to compute and extract the superclass
type.

Fixes the crasher from rdar://problem/26498438.
2018-06-14 15:28:36 -07:00
Brent Royal-Gordon
27dfa51be5 Wrap interpolated tuples in parens
Keeps them from being interpreted as parameter lists. Fixes SR-7958.
2018-06-13 22:55:48 -07:00
Robert Widmann
dfe42d2e55 Revert "Reject bad string interpolations (#17074)"
This reverts commit fc23f3404d.
2018-06-13 15:06:33 -07:00
Brent Royal-Gordon
fc23f3404d Reject bad string interpolations (#17074)
* Reject bad string interpolations

String interpolations with multiple comma-separate expressions or argument labels were being incorrectly accepted.

* Tweak error name to match message

* Diagnose empty interpolations more clearly

* Don’t double-diagnose parse errors

Fixes a test at Parse/recovery.swift:799 which the previous commit broke.

* Fix incorrect test RUN: line

A previous version of this test used FileCheck instead of -verify, and the run line wasn’t properly corrected to use -verify.

* Update comment

* Add more argument label tests

Ensures that we don’t get different results from an initializer that doesn’t exist or doesn’t take a String.

* Resolve the SR-7958 crasher test

We now diagnose the error and remove the label before it has an opportunity to crash.
2018-06-12 18:46:52 -07:00
Brent Royal-Gordon
16cc543eb3 Correct run line on unfixed crasher 2018-06-10 22:52:03 -07:00
Brent Royal-Gordon
2e8d0925fb Add reduced crasher for SR-7958
Trying to use an argument label in an interpolation can cause various crashes. In swiftlang-1000.0.16.7, these are usually in SILGen; in master at 8f6028d, they’re in CSApply.
2018-06-10 21:44:24 -07:00
Pavel Yaskevich
11ba7e0f42 [CSSimplify] When trying to simplify bind with error type fail gracefully
Since member lookup doesn't check requirements
it might sometimes return types which are not
visible in the current context e.g. typealias
defined in constrained extension, substitution
of which might produce error type for base, so
assignement should thead lightly and just fail
if it encounters such types.

Resolves: rdar://problem/39931339
Resolves: SR-5013
2018-05-28 00:24:54 -07:00
Doug Gregor
8d2ca387ef The test case from rdar://problem/31164540 is also fixed. 2018-04-20 11:15:22 -07:00
Slava Pestov
6f65d3d0a2 compiler_crashers_2/0153-rdar39130543.swift requires asserts 2018-04-19 14:09:56 -07:00
Doug Gregor
fec93f991c Add reduced, crashing test case for rdar://problem/39130543. 2018-04-16 11:25:34 -07:00
Huon Wilson
d33a5c16f2 [Sema] Explicit error for "extension GenericClass : ObjcProtocol".
If there was any requirements in the @objc protocol, the user got an error in
some form (a complaint about those requirements), but giving the direct error is
better, and handles @objc protocol with no requirements.

Also, fix a hole in that existing @objc method check: in `class Outer<T> { class
Inner {} }`, Inner should be considered generic, but the loop that was checking
for this didn't consider it.

Fixes https://bugs.swift.org/browse/SR-7370 and rdar://problem/39239512.
2018-04-13 08:09:02 +10:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Arnold Schwaighofer
66a2f5d05d Disable test that fails on linux asan bot
rdar://26498438
2017-11-27 14:35:06 -08:00
Slava Pestov
ccfa6e43f5 Add a crasher 2017-11-01 21:48:07 -07:00
Jordan Rose
dab697186b [test] Mark this recently-added crasher as requiring assertions. (#12284)
Added in Doug's f0e244cc.
2017-10-04 19:22:37 -07:00
Doug Gregor
b42585b98d Add crashing test case from SR-5546. 2017-10-04 10:51:55 -07:00