Commit Graph

861 Commits

Author SHA1 Message Date
Slava Pestov
8db0af48bd Merge pull request #71352 from slavapestov/remove-redundant-requirements
Remove -warn-redundant-requirements flag
2024-02-03 08:28:02 -05:00
Kavon Farvardin
3908c8182d NCGenerics: sometimes synth. Copyable/Escapable
When the Swift module is not available, we'll synthesize the
Copyable/Escapable decls into the Builtin module.

In the future, it might be nice to just do this always, and define
typealiases for those types in the stdlib to refer to the ones in the
builtin module.
2024-02-02 18:47:03 -08:00
Slava Pestov
d2f136254e AST: Remove fromDefault and inferred from StructuralRequirement 2024-02-02 14:57:20 -05:00
Slava Pestov
dcca5ced0f RequirementMachine: Remove -warn-redundant-requirements flag 2024-02-02 14:57:19 -05:00
Slava Pestov
9e247469a1 Sema: Implement new behavior of extensions with non-copyable generics
We want extensions to introduce default Copyable/Escapable just like
other generic contexts, so that once Optional adopts ~Copyable,
an `extension Optional` actually adds `Wrapped: Copyable` by default.
2024-01-31 21:56:45 -05:00
Kavon Farvardin
a2defd5367 [NCGenerics] fix AnyObject and inverses
resolves rdar://120512544
2024-01-10 19:37:21 -08:00
Kavon Farvardin
a9b2725520 [NFC] fast-path to skip a requirement scan 2024-01-10 19:37:21 -08:00
Slava Pestov
026d3f0078 Merge pull request #70311 from slavapestov/type-witness-system-inference-stdlib
Get the standard library to build with -enable-experimental-associated-type-inference
2023-12-10 17:50:33 -05:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
Slava Pestov
5dd8307e60 AST: Pass SubstOptions to DependentMemberType::substBaseType() 2023-12-07 18:00:50 -05:00
Kavon Farvardin
81ea9981c8 Merge pull request #69842 from kavon/ncgenerics-stdlib-building
[NCGenerics] more work towards getting the stdlib building
2023-11-29 17:31:45 -08:00
Pavel Yaskevich
5bc6ec6184 Merge pull request #69890 from xedin/rdar-99758612
[ClangImporter] Add support for `swift_attr(“@Sendable”)` on ObjC protocols
2023-11-27 13:17:31 -08:00
Pavel Yaskevich
ab4f8d0dc0 [RequirementMachine] Inherited requirements collection should account for synthesized protocols
ClangImporter adds `SynthesizedProtocolAttr` to model inheritance
from `Sendable` on protocols imported from Objective-C.
2023-11-16 10:58:34 -08:00
Kavon Farvardin
2cd298926f [NCGenerics] fix existential conformances
I was not expanding default requirements in
AbstractGenericSignatureRequest or ExistentialLayout.

Also fixes printing of composition types.
2023-11-15 15:43:11 -08:00
Slava Pestov
6bb74ab701 RequirementMachine: Fix stray } in RewriteSystem::dump() 2023-11-14 15:46:58 -05:00
Slava Pestov
08f8781798 RequirementMachine: Don't drop errors on the floor with @objc protocols 2023-11-14 15:46:43 -05:00
Slava Pestov
39ec9903e8 RequirementMachine: Untangle requirement desugaring from requirement inference
Refactor the code to match what's written up in generics.tex.

It's easier to understand what's going on if requirement inference
first introduces a bunch of requirements that might be trivial,
and then all user-written and inferred requirements are desugared
at the end in a separate pass.
2023-11-14 15:46:33 -05:00
Kavon Farvardin
455fcdc5e0 [Sema] add redundant ~Copyable requirement warning
Originally I tried to implement a fancy redundant-inverse error
diagnostic that identifies the "previous" requirement already seen. I
ended up removing this error diagnostic because it was tricky to
implement well and we weren't diagnosing other redundant requirements.

Turns out we do have a mode of the compiler to diagnose redundant
requirements, but as warnings, using `-warn-redundant-requirements`.
This warning is much simpler in that it just points to one requirement
that is redundant.
2023-11-06 15:38:10 -08:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07:00
Kavon Farvardin
4334279233 [nfc] clean and jot down some TODOs 2023-10-28 16:12:55 -07:00
Slava Pestov
e081154eb3 RequirementMachine: Fix for FunctionType canonicalization subtlety
We assumed that replacing a subcomponent of a CanType with another
CanType always produces a CanType. This is no longer true because
() throws(Never) -> () canonicalizes down to () -> ().
2023-10-27 21:15:06 -04:00
Kavon Farvardin
2e66b69953 [Sema] prevent inverse-constraints on outer params
Since there is no propagation of inverse constraints in the requirement
machine, we need to fully desugar these requirements at the point of
defining a generic parameter. That desugaring involves determining which
default conformance requirements need to be applied to a generic
parameter, accounting for inverses.

But, nested generic contexts in scope of those expanded generic
parameters can still write constraints on that outer parameter. For
example, this method's where clause can have its own constraints on `T`:

```
struct S<T> {
 func f() where T: ~Copyable {}
}
```

But, the generic signature of `S` already has a `T: Copyable` that was
expanded. The method `f` will always see a `T` that conforms to
`Copyable`, so it's impossible for `f` to claim that it applies for
`T`'s that lack Copyable.

Put another way, it's not valid for this method `f`, whose generic
signature is based on its parent's `S`, to weaken or remove requirements
 from parent's signature. Only positive requirements can be
 added to them.
2023-10-27 15:01:10 -07:00
Kavon Farvardin
bb341e7928 [NoncopyableGenerics] fix isNoncopyable for packs
We're not yet going to allow noncopyable types into packs, so this
change prevents the use of `~Copyable` on an `each T` generic parameter.
 It also fixes how we query for whether a `repeat X` parameter is
 copyable.
2023-10-27 15:01:10 -07:00
Kavon Farvardin
a92181827a [Sema] handle inverses everywhere
Previously, inverses were only accounted-for in inheritance clauses.

This batch of changes handles inverses appearing in other places, like:

- Protocol compositions
- `some ~Copyable`
- where clauses

with proper attribution of default requirements in their absence.
2023-10-27 15:01:10 -07:00
Doug Gregor
d3ede19150 Generalize inference of Error type requirements from typed throws 2023-10-27 12:52:07 -07:00
Kavon Farvardin
695b07dadc [nfc] simplify inverse matching 2023-10-23 10:37:22 -07:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Kavon Farvardin
f76360c5b1 [Sema] "Noncopyable" means no Copyable conformance 2023-10-18 13:52:14 -07:00
Evan Wilde
312bd47f4c Merge remote-tracking branch 'main' into 'rebranch' 2023-10-16 23:00:12 -07:00
Mishal Shah
3594f8ecaf Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	test/IRGen/opaque-pointer-llvm.swift
2023-10-15 23:49:40 -07:00
Doug Gregor
b51ad81bbe [Typed throws] Address comments about inferring Error conformances 2023-10-15 22:59:48 -07:00
Doug Gregor
2d7eafd155 Infer error conformance for type parameters used in typed throws
The type that occurs as the thrown error type must conform to the
`Error` protocol. Infer this conformance when the type is a type
parameter in the signature of a function.
2023-10-13 16:09:44 -07:00
swift-ci
72e3d66404 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-23 15:35:20 -07:00
Kavon Farvardin
0944d46e65 [nfc] fix spelling; invertable -> invertible 2023-09-22 17:04:57 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -07:00
Kavon Farvardin
a69bcf8a61 Merge pull request #67930 from kavon/copyable-requirement
Copyable as a Requirement Against the Machine
2023-09-21 11:49:23 -07:00
Kavon Farvardin
80097bce0c [Generics] ~Copyable in inheritance clauses
Have `~Copyable` change the signatures of a generic type param,
protocol, or associated type if written in the inheritance clause
position.
2023-09-21 00:55:17 -07:00
swift-ci
5a9893a62a Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 14:34:28 -07:00
Slava Pestov
e4057a46b7 Merge pull request #68633 from slavapestov/fix-rdar115538386
RequirementMachine: Pass SubstFlags::PreservePackExpansionLevel when re-sugaring requirements
2023-09-20 09:19:09 -04:00
Slava Pestov
dc2e0c95db RequirementMachine: Pass SubstFlags::PreservePackExpansionLevel when re-sugaring requirements 2023-09-19 23:11:05 -04:00
Slava Pestov
5990158d66 RequirementMachine: Don't allow PackExpansionType to sneak in 2023-09-19 22:34:37 -04:00
Kavon Farvardin
68ae729584 _Copyable as a Requirement Against the Machine
An initial implementation of a rework in how
we prevent noncopyable types from being
substituted in places they are not permitted.

Instead of generating a constraint for every
generic parameter in the solver, we produce
real Copyable conformance requirements. This
is much better for our longer-term goal of
supporting `~Copyable` in more places.
2023-09-19 16:35:17 -07:00
swift-ci
0407c3d3b2 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-06 13:34:53 -07:00
Allan Shortlidge
01ecd81950 AST: Introduce conveniences for inheritance clause source locations.
Replace the `front()` and `back()` accessors on `InheritedTypes` with dedicated
functions for accessing the start and end source locations of the inheritance
clause. NFC.
2023-09-06 10:41:57 -07:00
Allan Shortlidge
c884632312 AST: Consolidate inherited type resolution.
Move evaulation of `InheritedTypeRequest` into the `InheritedTypes` wrapper.
NFC.
2023-09-06 10:41:57 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
swift-ci
39b640ce1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-31 09:05:17 -07:00
Slava Pestov
f3748133a6 RequirementMachine: Add missing entry to Symbol::Kinds
When we added same-shape requirements, we broke -analyze-requirement-machine,
which outputs some histograms. Add a regression test to make sure this code
path doesn't bitrot.
2023-08-29 22:44:24 -04:00
swift-ci
a16cc7eb8d Merge remote-tracking branch 'origin/main' into rebranch 2023-08-22 06:13:49 -07:00