Commit Graph

861 Commits

Author SHA1 Message Date
Sima Nerush
0dc6719748 [Requirement Machine] Fix the order of terms with pack element symbols to always appear on the left-hand side of the same-element rewrite rule. 2024-07-15 10:19:32 -07:00
Sima Nerush
1ba38c54f2 [Requirement Machine] When forming requirements from same-element rewrite rules, swap the sides depending on which one is longer once the [element] symbol is dropped.
This change fixes the "out-of-order" type parameters error in `GenericSignature::verify`
2024-07-15 10:19:32 -07:00
Sima Nerush
10a4940396 [Requirement Machine] Add ability to prepend a symbol to a term, clean up existing code 2024-07-15 10:19:32 -07:00
Sima Nerush
6393a32a68 [Requirement Machine] Initialize storage for ThePackElementSymbol 2024-07-15 10:19:32 -07:00
Holly Borla
dbda2738a6 [Features] Gate same-element requirements behind an experimental feature flag. 2024-07-15 10:19:32 -07:00
Holly Borla
e6eb5dab79 [Requirement Machine] Stricter verification conditions for element symbols. 2024-07-15 10:19:32 -07:00
Holly Borla
eabaed8a62 [Requirement Machine] Use element symbols for concrete same-element requirements. 2024-07-15 10:19:32 -07:00
Holly Borla
0b6f8c8bd0 [Requirement Machine] Fix the order of requirements that involve pack elements. 2024-07-15 10:19:32 -07:00
Holly Borla
2ea4586580 [Requirement Machine] Implement same-element requirements. 2024-07-15 10:19:32 -07:00
Ben Barham
2715d0e9d6 Merge branch 'main' into 20240710-main-to-rebranch
Conflicts:
  - `test/Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-itanium.swift`
    previously fixed on rebranch, now fixed on main (slightly differently).
2024-07-10 20:42:09 -07:00
Slava Pestov
2adad14f7b RequirementMachine: Don't call getContextSubstitutionMap() on an existential type 2024-07-10 13:28:26 -04:00
swift-ci
b7921a8232 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-06 14:34:09 -07:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
1901862afc AST: Remove LookUpConformanceInSignature 2024-07-06 12:05:46 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Ben Barham
aa7a3a8268 Cleanup std includes
Remove `deque` from files it isn't actually used in. Add it and `stack`
to files that it is - presumably they were previously transitively found
through other includes.
2024-07-02 16:13:49 -07:00
Slava Pestov
f34e57c016 RequirementMachine: Use ProtocolDecl::getAllInheritedProtocols() 2024-06-25 15:20:42 -04:00
Slava Pestov
273c4b2b1a RequirementMachine: Convert to new assertions 2024-06-22 08:53:22 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Kavon Farvardin
ec4a125f3e NCGenerics: ext's might not infer invertible req's
If the extension adds conformance to an invertible protocol, it's
confusing for people to also infer conditional requirements on the
generic parameters for those invertible protocols. This came up in the
review of SE-427.
2024-06-12 14:44:22 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Slava Pestov
04d3d43c4a RequirementMachine: Better assertion when root type parameter is invalid
Previously getReducedType() would dump debug info if we had an invalid
dependent member type, but an invalid root type parameter would cause
a segfault. Fix this.
2024-05-02 13:40:43 -04:00
Kavon Farvardin
779184f922 NCGenerics: fix reverse condfail
I gated inverses on associated types behind a feature flag, but a
slightly older stdlib being rebuilt from source will now fail because it
 used that functionality for `_Pointer` without the feature.

So, just permit the feature if we're working with a module built from
an interface file, to avoid this reverse condfail
.
2024-04-18 15:01:24 -07:00
Slava Pestov
454e5cff67 Merge pull request #72825 from slavapestov/two-minor-fixes-and-tests
RequirementMachine: Fix two minor crash on invalid bugs
2024-04-03 22:42:24 -04:00
Slava Pestov
ae73cd4637 RequirementMachine: Fix an incorrect assertion
We don't expect to see type parameters that are not generic parameters
here, but dependent member types that wrap an ErrorType are fine, they
show up when a conformance had an invalid type witness.

Fixes the remaining example from https://github.com/apple/swift/issues/59384.
2024-04-03 19:37:20 -04:00
Slava Pestov
61dbaf892d RequirementMachine: Fix crash with protocol typealias having unbound generic type
Make sure we don't try to introduce an implicit same-type requirement
in this case.

Fixes rdar://problem/63731199.
2024-04-03 17:47:39 -04:00
Kavon Farvardin
30983530b6 NCGenerics: introduce SuppressedAssociatedTypes
The model for associated types hasn't been fully worked-out for
noncopyable generics, but there is some support already that is being
used by the stdlib for an internal-only (and rather cursed) protocol
`_Pointer` to support `UnsafePointer`, etc.

This patch gates the existing experimental support for associated types
behind a feature flag. This flag doesn't emit feature-guards in
interfaces, since support for it is tied closely to NoncopyableGenerics
and has been there from its early days.
2024-04-02 16:53:36 -07:00
Doug Gregor
79b78acdf6 Use SuppressibleProtocolSet as InvertibleProtocolSet
Collapse the representations of "suppressible" and "invertible"
protocol sets. Only minor adjustments were required.
2024-03-29 11:31:48 -07:00
Slava Pestov
bee9fee58b RequirementMachine: Don't call ProtocolDecl::getSuperclass() in concrete contraction
This changes the minimized signature in a very narrow edge case.

If you have

    class C : P {}

and also

    protocol P : C {}
    protocol P where Self : C {}

then <T where T : P, T : C> now becomes <T : P> both with spellings;
before, the first one gave <T : P> and the second <T : C>.
2024-03-21 14:49:05 -04:00
Kavon Farvardin
149c052ec5 use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is
mature enough to be used.
2024-03-14 23:10:44 -07:00
Slava Pestov
10a2ddb95e RequirementMachine: Fix MaxConcreteNesting check to take initial rules into account
Fixes rdar://123357717.
2024-03-06 21:42:49 -05:00
Slava Pestov
5f2c49bd0e RequirementMachine: Canonicalize protocol list in RequirementMachine::getLocalRequirements() 2024-02-29 18:13:28 -05:00
Slava Pestov
1b99dd2451 RequirementMachine: Tweak RewriteSystem::recordConflict() heuristic again 2024-02-29 18:13:28 -05:00
Slava Pestov
cfa557e5d1 RequirementMachine: Refactor RequirementBuilder a bit 2024-02-29 18:13:28 -05:00
Slava Pestov
4a1b0c80cd RequirementMachine: Install placeholder requirement signature if completion fails
I did this if there was a request cycle but forgot the other obvious case.
2024-02-29 18:13:28 -05:00
Slava Pestov
76670472dc AST: Remove InverseRequirement::enumerateDefaultedParams() 2024-02-24 07:25:59 -05:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Slava Pestov
e7d7f6f69f RequirementMachine: Add Copyable/Escapable requirements to 'placeholder' generic signatures
If we fail to build a generic signature (or requirement signature of a
protocol) because of a request cycle or because Knuth-Bendix completion
failed, we would create a placeholder signature with no requirements.

However in a move-only world, a completely unconstrained generic
parameter might generate spurious diagnostics when used in a copyable
way. For this reason, let's outfit these placeholder signatures with
a default set of conformance requirements to Copyable and Escapable.
2024-02-20 18:26:05 -05:00
Slava Pestov
7e4761a751 Merge pull request #61064 from slavapestov/rqm-conflicting-rules-can-remain
RequirementMachine: Leave behind conflicting requirements in the minimized signature
2024-02-15 18:08:09 -05:00
Slava Pestov
70c9f8a47e RequirementMachine: Leave behind conflicting requirements in the minimized signature
Requirement lowering only expects that it won't see two requirements
of the same kind (except for conformance requirements). So only mark
those as conflicting.

This addresses a crash-on-invalid and improves diagnostics for
move-only generics, because a conflict won't drop the copyability
of a generic parameter and expose a move-only-naive user to
confusing error messages.

Fixes #61031.
Fixes #63997.
Fixes rdar://problem/111991454.
2024-02-15 14:32:31 -05:00
Kavon Farvardin
63ed8ec4a6 NCGenerics: handle legacy definition of Sendable
This should be a temporary measure while bootstrapping the feature.
2024-02-15 11:07:49 -08:00
Kavon Farvardin
e8b4813dae RequirementMachine: fix allowInverses handling
We were skipping the expansion of default requirements on generic
parameters when creating an abstract generic signature that adds only
new generic parameters, but no additional requirements.
2024-02-14 13:34:35 -08:00
Slava Pestov
4f1d8e3746 Sema: Clean up InferredGenericSignatureRequest
- It's wasteful to cache because each invocation is unique
- Inference sources only need to be Types and not TypeLocs
- We can pass in an explicit SourceLoc for diagnostics

(cherry picked from commit 4e39dac206dd8e0818ca509f5f09f93425a48c62)
2024-02-09 16:02:32 -08:00
Slava Pestov
25355b2b57 Sema: Don't re-sugar the type in StructuralTypeRequest::evaluate()
(cherry picked from commit 1db69ab2485d5d61ecdceaf6f10720378b149dda)
2024-02-09 16:02:15 -08:00
Kavon Farvardin
c8bf35ab96 NCGenerics: precedence of inverses & reqirements
With the removal of `fromDefault` in StructuralRequirement,
`applyInverses` no longer could distinguish which reqirements came from
`expandDefaults` and which were explicitly written in source. Thus, for
a generic parameter like `<T> where T: Copyable, T: ~Copyable`, the
inverse `~Copyable` was eliminating the explicitly-written requirement,
causing `T` to be noncopyable.

We want to emit an error in such cases, so this swaps things around so
we only ever applyInverses on a requirements list that is from
expandDefaults.
2024-02-08 13:43:49 -08:00
Slava Pestov
d46bd335de Merge pull request #71371 from slavapestov/ncgenerics-fixes-3
Non-copyable generics fixes, part 3
2024-02-06 08:35:07 -05:00
Slava Pestov
af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Slava Pestov
4e84d28670 SIL: Build substitution signature without expanding defaults or applying inverses 2024-02-05 18:43:06 -05:00
Hamish Knight
05615fa0e4 NFC: Rename TypeWalker's SkipChildren to SkipNode
For consistency with ASTWalker.
2024-02-05 15:27:25 +00:00
Kavon Farvardin
a816489024 RequirementLowering: remove assert
Finding a structural requirement that is not involving an invertible
protocol is not suspicious at all.
2024-02-04 19:57:29 -08:00