Commit ceff414
committed
Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`. I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.
Distinguishing the substitutions has two chief advantages over the existing representation. First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use. More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.
As an example of the latter, consider the following protocol conformance:
```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```
The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`. Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way. With this change, the lowered signature of this witness could be `<T> @Substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.
When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods. This patch does not actually take that step, however; it merely makes it possible to do so.
As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type. This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.
My plan is to start by producing substituted function types for accessors. Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of. They're also used in narrower ways that should exercise less of the optimizer.1 parent adbf8da commit ceff414
File tree
96 files changed
+1256
-624
lines changed- docs
- ABI
- include/swift
- AST
- Demangling
- SIL
- lib
- AST
- Demangling
- IRGen
- ParseSIL
- Parse
- SILGen
- SILOptimizer
- FunctionSignatureTransforms
- IPO
- Transforms
- UtilityPasses
- Utils
- SIL
- Sema
- Serialization
- test
- IRGen
- Reflection
- SILGen
- SILOptimizer
- SIL
- Parser
- Serialization
- Sema/fixed_ambiguities
- stdlib
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
96 files changed
+1256
-624
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
586 | | - | |
| 586 | + | |
587 | 587 | | |
588 | | - | |
| 588 | + | |
589 | 589 | | |
| 590 | + | |
| 591 | + | |
590 | 592 | | |
591 | 593 | | |
592 | 594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
595 | 635 | | |
596 | 636 | | |
597 | 637 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
831 | 839 | | |
832 | 840 | | |
833 | 841 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4019 | 4019 | | |
4020 | 4020 | | |
4021 | 4021 | | |
| 4022 | + | |
| 4023 | + | |
4022 | 4024 | | |
4023 | 4025 | | |
4024 | 4026 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
476 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
477 | 478 | | |
478 | 479 | | |
479 | | - | |
480 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
481 | 484 | | |
482 | 485 | | |
483 | 486 | | |
| |||
487 | 490 | | |
488 | 491 | | |
489 | 492 | | |
490 | | - | |
491 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
492 | 496 | | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
497 | 501 | | |
498 | 502 | | |
499 | 503 | | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
503 | | - | |
504 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
505 | 524 | | |
506 | 525 | | |
507 | 526 | | |
| |||
0 commit comments