Commit Graph

33 Commits

Author SHA1 Message Date
Joe Groff
e4a6faa3f2 Sema: Allow T == NonCopyableOrEscapable same-type constraints without a redundant T: ~Copyable.
Enhance the logic in `applyInverses` to also take into account same-type constraints spelled in
the generic signature, so that same-type-constraining a type parameter to a type that is itself
not `Copyable` or `Escapable` suppresses the default application of those constraints on the
type parameter. Fixes rdar://147757973.
2025-05-13 11:31:41 -07: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
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
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
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
Holly Borla
679825063a [RequirementMachine] Only skip Sendable requirements inferred from preconcurrency
decls if the decl we're inferring the generic signature for is not itself
preconcurrency.
2023-01-19 20:28:50 -08:00
Slava Pestov
f901cc72b4 RequirementMachine: Move diagnostics code into a new Diagnostics.cpp 2022-05-10 01:49:56 -04:00
Slava Pestov
bc43cdd104 RequirementMachine: Generalize hack that allows associated type inheritance clauses to reference protocol typealiases
We want to allow this for all conformance requirements written in protocols
or the `where` clause of protocol extensions.

Fixes rdar://problem/91304291.
2022-04-05 18:42:35 -04:00
Slava Pestov
d385b73cd6 RequirementMachine: Plumb source locations through concrete contraction 2022-04-01 22:33:03 -04:00
Slava Pestov
75161ce6b0 RequirementMachine: Tweak fixit that turns 'T : Int' into 'T == Int' slightly to match GSB 2022-04-01 01:05:54 -04:00
Slava Pestov
ef1636a462 RequirementMachine: Split off RuleBuilder.{cpp,h} from RequirementLowering.{cpp,h} 2022-03-16 12:24:20 -04:00
Slava Pestov
7c006190dd RequirementMachine: Fold getRuleForRequirement() into RuleBuilder::addRequirement() 2022-03-16 12:24:20 -04:00
Slava Pestov
652de97cfd RequirementMachine: Introduce RuleBuilder::initWithConditionalRequirements() 2022-03-16 12:24:20 -04:00
Slava Pestov
327e7e580b RequirementMachine: Add importedRules parameter to RewriteSystem::initialize() 2022-03-16 00:58:30 -04:00
Slava Pestov
aaf84ac6c2 RequirementMachine: Implement RequirementMachine::initWithProtocolSignatureRequirements() 2022-03-15 18:34:54 -04:00
Slava Pestov
564f626f62 RequirementMachine: Rename some RuleBuilder methods for clarity 2022-03-15 18:34:54 -04:00
Slava Pestov
1d8dd94501 RequirementMachine: Refactor RuleBuilder in preparation for rule sharing 2022-03-15 18:34:54 -04:00
Slava Pestov
1f125c3b5b RequirementMachine: Make some methods on RuleBuilder private 2022-03-15 18:34:54 -04:00
Holly Borla
b18e815436 [RequirementMachine] Preserve structural requirements during rule construction,
and diagnose trivially redundant rules in the rewrite system.
2022-03-09 12:14:58 -08:00
Slava Pestov
8e09ba8b45 RequirementMachine: Introduce 'concrete contraction' pre-processing pass before building rewrite system
See the comment at the top of ConcreteContraction.cpp for a detailed explanation.

This can be turned off with the -disable-requirement-machine-concrete-contraction
pass, mostly meant for testing. A few tests now run with this pass both enabled
and disabled, to exercise code paths which are otherwise trivially avoided by
concrete contraction.

Fixes rdar://problem/88135912.
2022-02-25 11:48:38 -05:00
Holly Borla
a992917f1c [NFC][RequirementMachine] Rename some of the RequirementError::Kind cases,
add documentation for each case, and move RequirementError to
lib/AST/RequirementMachine/Diagnostics.h.
2022-02-16 13:11:57 -08:00
Holly Borla
3837b4def4 [RequirementMachine] Diagnose early redundant requirements. 2022-02-16 13:11:57 -08:00
Holly Borla
3c2b588037 [RequirementMachine] Plumb the requirement errors vector through desugarRequirement. 2022-02-16 13:11:57 -08:00
Holly Borla
a74717ab69 [RequirementMachine] Diagnose non-protocol, non-class conformance/subtype
constraints in the requirement machine.
2022-02-16 13:11:56 -08:00
Slava Pestov
4a06e21bf9 RequirementMachine: Introduce rules for protocol typealiases from requirement signatures
When building a rewrite system for a generic signature or protocol,
we would add requirements from the requirement signature of every
protocol dependency. Now, also add protocol typealias rules as well.
2022-02-13 00:24:23 -05:00
Slava Pestov
10e4ffdfbd RequirementMachine: Track known protocols in the rewrite system
Conditional requirement inference needs to be able to add rewrite rules
from the requirement signatures of hitherto-unseen protocols, so to
help with that, extract out the RuleBuilder's ProtocolMap and move it
into the RewriteSystem.
2022-01-25 00:35:03 -05:00
Slava Pestov
96122834fb RequirementMachine: getRuleForRequirement() supports relative terms 2022-01-25 00:32:25 -05:00
Slava Pestov
f480eeaf53 RequirementMachine: Factor out getRuleForRequirement() from RuleBuilder::addRequirement() 2022-01-25 00:32:25 -05:00
Slava Pestov
291ddd7a31 RequirementMachine: Plumb through the ModuleDecl used for requirement inference 2021-11-29 13:54:15 -05:00
Slava Pestov
42c0a28ad7 RequirementMachine: Add RequirementMachine::initWithWrittenRequirements() 2021-11-19 15:48:28 -05:00
Slava Pestov
f0899e3acb RequirementMachine: Make some entry points in RequirementLowering.cpp public 2021-11-19 15:48:07 -05:00
Slava Pestov
df8ce67539 RequirementMachine: Refactor requirement lowering 2021-11-12 14:30:46 -05:00
Slava Pestov
ff5d0e1d63 RequirementMachine: Split off RuleBuilder into a new RequirementLowering.cpp file 2021-11-12 14:30:46 -05:00