Commit 0c34994
committed
Fix #8250: Allow Expr.betaReduce to rewrite type ascriptions
When a blackbox inline def is inlined, a type ascription is added to preserve the apparent return type
of the inline def. Prior to this commit, the quoted.Expr.betaReduce function was unable to properly
inline a known lambda expression coming from an inline def as it would see the type ascription and
give up.
This change makes betaReduce rewrite type ascriptions, allowing it to inline type-ascribed functions such as those coming
from inlined defs.
- When type ascriptions are not present, behaviour does not change.
- When type ascriptions are encountered, the outermost ascription is kept.
- If the inline is successful, then the result type of the ascribed function type is ascribed to the inlined body.
- If the inline is not successful, the outermost ascribed type is re-ascribed to the non-inlineable expression before
inserting a call to that expression.
There are several test cases, covering:
- verifying that betaReduce can correctly reduce the application of the result of an inline def
to a constant value, with the reduction result being printed using the `compiletime.code` interpolator.
- verifying that the result type ascription handles dependent function types
- inserting ??? as either the inlined body or a function expression that cannot be inlined compiles without error (by
re-ascribing the apparent type)
- a neg-test that a function whose type is `Int=>Int` and whose body inlines to `4` does not typecheck against the
singleton type `4`.1 parent abaf47e commit 0c34994
File tree
7 files changed
+109
-6
lines changed- compiler/src/dotty/tools/dotc/tastyreflect
- tests
- neg-macros
- beta-reduce-inline-result
- run-macros
- beta-reduce-inline-result
7 files changed
+109
-6
lines changedLines changed: 26 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2042 | 2042 | | |
2043 | 2043 | | |
2044 | 2044 | | |
2045 | | - | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
2046 | 2052 | | |
2047 | 2053 | | |
2048 | | - | |
| 2054 | + | |
2049 | 2055 | | |
2050 | 2056 | | |
2051 | 2057 | | |
2052 | | - | |
| 2058 | + | |
2053 | 2059 | | |
2054 | 2060 | | |
2055 | 2061 | | |
2056 | 2062 | | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
2057 | 2073 | | |
2058 | | - | |
| 2074 | + | |
2059 | 2075 | | |
2060 | | - | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
2061 | 2081 | | |
2062 | | - | |
| 2082 | + | |
2063 | 2083 | | |
2064 | 2084 | | |
2065 | 2085 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments