Commit Graph

223 Commits

Author SHA1 Message Date
Joe Groff
a83349bcab Merge pull request #24875 from jckarter/opaque-type-subst-assertion
AST: Cut a different corner when building GenericEnvironments for OpaqueTypeArchetypeTypes.
2019-05-20 08:12:54 -07:00
Joe Groff
eeeb46956f AST: Cut a different corner when building GenericEnvironments for OpaqueTypeArchetypeTypes.
Because opaque types are currently limited so that they only have immediate
protocol constraints, and therefore don't interact with the outer generic
parameters at all, we can get away without adding same-type constraints for
the outer generic parameters to their substitutions in the generic signature
builder when setting up the environment for an opaque archetype. This
avoids the strict assertion that opaque types not appear in other decls'
interface types. rdar://problem/50509030

Adding where clauses would break this hack.
2019-05-17 16:19:13 -07:00
Pavel Yaskevich
17643a30e0 [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-17 12:53:27 -07:00
Pavel Yaskevich
d4e8d583ae Revert "[ConstraintSystem] Use missing conformance fix to diagnose contextual failures" 2019-05-17 12:45:55 -07:00
Pavel Yaskevich
5fb3a8ba30 Merge pull request #24754 from xedin/diag-missing-contextual-conformances
[ConstraintSystem] Use `missing conformance` fix to diagnose contextual failures
2019-05-17 11:40:49 -07:00
Joe Groff
0be95f56bd Merge pull request #24798 from jckarter/opaque-type-check-availability
Opaque types require a newer Swift runtime.
2019-05-15 18:05:40 -07:00
Pavel Yaskevich
d5c561b44e [ConstraintSystem] Move missing contextual protocol detection to matchExistentialTypes 2019-05-15 15:37:36 -07:00
Joe Groff
cec9e9e33a Opaque types require a newer Swift runtime.
Check the availability of decls that declare an opaque return type to ensure they deploy to a
runtime that supports opaque types.

rdar://problem/50731151
2019-05-15 11:39:53 -07:00
Joe Groff
1d6aca4e93 Add regression test that opaque underlying type checking does not look in closures 2019-05-14 10:06:00 -07:00
Joe Groff
001c0dda76 Merge pull request #24485 from jckarter/opaque-type-signature-gsb
Sema: Use GSB to build the signature for opaque result type decls.
2019-05-03 17:59:43 -07:00
Joe Groff
a58bc8a320 Sema: Use GSB to build the signature for opaque result type decls.
Our ad-hoc mechanism for building the signature did not always produce requirements in the order
expected by the rest of the system; using the GSB should ensure we build a valid generic signature.
Fixes rdar://problem/50309983.
2019-05-03 15:01:02 -07:00
Pavel Yaskevich
caad4a817b [MiscDiagnostics] Run opaque return checker only if all of the return expressions are correct 2019-04-29 18:42:28 -07:00
Pavel Yaskevich
1f1e8d99d7 [Diagnostics] Improve missing conformance diagnostics for opaque return
New diagnostic framework can already identify contextual failures
related to opaque return types, `RequirementFailure` just needs
to get adjusted to identify correct affected declaration and provide
tailored diagnostic.

Resolves: rdar://problem/49582531
2019-04-29 16:17:45 -07:00
nate-chandler
6352764075 Merge pull request #24271 from nate-chandler/nate/49581931-opaque-implicit-return-constraint
Create opaque type constraint for single expr return. [49581931]
2019-04-26 15:27:46 -07:00
Nate Chandler
bf42fbdf95 Expected diagnostic around failure to convert Never to opaque. 2019-04-25 14:32:39 -07:00
Joe Groff
b2d50c86b7 Sema: don't consider opaque types distinct for overloading purposes.
This is necessary because:

```
func foo() -> some P
func foo() -> some P
```

theoretically defines two distinct return types, but there'd be no way to disambiguate them. Disallow overloading only by opaque return type.
2019-04-25 14:28:56 -07:00
Joe Groff
0fcc7cdac0 Check the underlying type of get-only computed properties with opaque return types. 2019-04-17 14:46:22 -07:00
Joe Groff
59fd141457 Validate opaque return types for properties and subscripts. 2019-04-17 14:46:22 -07:00
Joe Groff
be0140fe56 Switch __opaque to some, per the latest rev of the proposal 2019-04-17 14:46:21 -07:00
Joe Groff
6db0540b8a Sema: Don't allow properties with inferred types to infer opaque result types.
This prevents opaque result types from propagating nontrivially into other declarations' types,
which may be confusing and create implementation complexities.
2019-04-17 14:43:32 -07:00
Joe Groff
7a8b9401ab Respond to Slava's feedback 2019-04-17 14:43:32 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
f008019bda Sema: Infer the underlying type for opaque return types from function bodies. 2019-04-17 14:43:32 -07:00
Joe Groff
dd2b51d6dc Add an OpaqueTypeArchetypeType subclass. 2019-04-17 14:43:32 -07:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Joe Groff
5e1497967a Parse opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
dff3f0d134 Merge pull request #23853 from johnno1962/Self-fallback-followup
Ban Self in typealias for now
2019-04-11 16:12:44 -04:00
John Holdsworth
8b64cd4031 Only so much is possible 2019-04-09 00:21:41 +01:00
John McCall
4f4d64b93e Various improvements to the variable-is-never-mutated diagnostic.
The main fixes here are:
- we weren't looking through open-existentials in the l-value
- we weren't handling mutating gets correctly unless CSApply wrapped
  the base in an InOutExpr, which seems to be multifile-sensitive
- we were missing diagnostics in some cases involving subscripts

A better fix would be to re-introduce LValueAccessKind, but I wanted
a workable short-term fix that I could try to get into 5.1.

Fixes rdar://49482742, which is specific to the lazy-getter problem.
2019-04-08 18:43:24 -04:00
John Holdsworth
c89ce55c9e Ban Self in typealias for now https://bugs.swift.org/browse/SR-10334 2019-04-08 10:44:09 +01:00
John Holdsworth
36ac824391 Tighten up test 2019-03-24 18:27:18 +00:00
John Holdsworth
c317fda15f Include test of error on declaring property with type Self 2019-03-22 13:48:39 +00:00
John Holdsworth
dbe99d771e Make Self available to member functions (SE-0068?) (#22863)
* Make Self available to instance member functions (SE-0068?)

* Works for value types and static functions.

* Further experiments with TypeExpr

* Move Self processing off diagnostic path

* diagnostic instead of assertion fail

* TypeExpr of DynamicSelfType now working.

* Update tests for availability of Self

* Cast to Self fixed!

* Self not available as type in classes except for return type

* Could it be this simple?

* Nearly there

* Fix function decls using Self inside methods.

* Fix validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* Fix of ./validation-test/compiler_crashers_2_fixed/0179-rdar44963974.swift

* "Un-fix" validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* CHANGELOG entry

* Update CHANGELOG.md

Co-Authored-By: johnno1962 <github@johnholdsworth.com>

* Update CHANGELOG.md
2019-03-15 23:23:19 -04:00
Nate Cook
5bd2b3e639 Use the term 'argument' instead of 'value' 2019-03-05 08:31:42 -06:00
Nate Cook
e32ad7830a Revise error for incorrect subscript parameters.
We use subscripts for more than just indexes in Swift these days, so
the error message needs to be a bit more general.
2019-02-15 15:25:50 -06:00
Brent Royal-Gordon
a72be0fb7d Sort overloads in suggestPotentialOverloads()
When the compiler fails to find an overload with suitable parameter or return types, it often attaches a note listing the available overloads so that users can find the one they meant to use. The overloads are currently ordered in a way that depends on the order they were declared, so swift-evolve would sometimes cause tests involving these diagnostics to fail.

This change emits the list in a textually-sorted order instead. The names were already being sorted as they were inserted into a std::set, so this shouldn’t significantly slow down the diagnostic.
2018-12-12 11:58:57 -08:00
Karoy Lorentey
666a22feff [test] Modernize hashing throughout the test suite 2018-11-29 17:38:29 +00:00
Slava Pestov
6903e716fd Sema: Diagnose unsupported existential types in more places
Fixes <rdar://problem/23427259>, <https://bugs.swift.org/browse/SR-4207>.
2018-11-16 01:18:18 -05:00
Pavel Yaskevich
16dfa6be72 [Diagnostics] Add superclass requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "superclass"
generic requirement failures.
2018-08-21 00:39:21 -07:00
Pavel Yaskevich
ba085e5bdc [Diagnostics] Improve missing conformance diagnostics for sub-types and members
If generic parameter associated with missing conformance comes
from different context diagnose the problem as "referencing" a
specific declaration from affected type.
2018-08-07 18:55:43 -07:00
Pavel Yaskevich
ad171e05cc [Diagnostics] Improve missing conformance diagnostics by using affected declaration
Instead of simply pointing out which type had conformance failures,
let's use affected declaration instead, which makes diagnostics much
richer e.g.

```
'List<[S], S.Id>' requires that 'S.Id' conform to 'Hashable'
```

versus

```
initializer 'init(_🆔)' requires that 'E' conform to 'Hashable' [with 'E' = 'S.Id']
```

Since latter message uses information about declaration, it can also
point to it in the source. That makes is much easier to understand when
problem is related to overloaded (function) declarations.
2018-08-07 12:59:53 -07:00
Pavel Yaskevich
f15e17a629 [Sema] NFC: reword "only concrete types can conform to protocols" diagnostic 2018-08-03 14:27:00 -07:00
Pavel Yaskevich
c2bf3d5ba9 [TypeChecker] NFC: Fix all of the diagnostics improved by conformance tracking 2018-08-02 21:55:16 -07:00
Slava Pestov
66e6a6a2c5 AST: Fix name lookup for protocols with superclasses
Also, start adding some tests now that basic things seem to work.
2018-07-06 23:39:39 -07:00
Slava Pestov
9ec1926731 Sema: Allow classes in protocol inheritance clauses 2018-07-02 22:06:33 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Robert Widmann
1beb75583a Push FunctionTypeRepr Input Invariants Up
Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding.  If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

- The SIL Parser no longer accepts Swift 2-style type declarations
-  Parse is more cleanly able to reject invalid FunctionTypeReprs
- Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks
2018-06-13 18:41:20 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00