Commit 4f39236
authored
Allow macro annotation to transform companion (#19677)
### Allow MacroAnnotations to update the companion of a definition
We extend the MacroAnnotation api to allow to modify the companion of a
class or an object.
### Specification
1. Order of expansion
- We expand the definitions in program order.
- We expand the annotations of the outer scope first, then we expand the
inner definitions.
- Annotations are expanded from the outer annotation to the inner
annotation.
In the following example, we expand the annotations in this order: `a1`,
`a2`, `a3`.
```scala
@A1 @a2
class Foo:
@A3 def foo = ???
```
2. Expansion of the companion
We always expand the latest available tree. If an annotation defined on
`class Foo` changes its companion (`object Foo`) and the `class` is
defined before `object`, the expansion of the annotations on the
`object` will be performed on the result of the expansion of `class`.
3. The program order is maintained
We maintain the program order in the definitions that were expanded.
4. Backtrack and reprocess
Example:
```scala
@A1 class Foo
@a2 object Foo
```
If the `@a2` annotation changes the definitions in `class Foo`, we will
rerun the algorithm on the result of this new expansion. Please note
that we don't allow to generate code with MacroAnnotations, the reason
for rerunning the algorithm is to expand and inline possible macros that
we generated.
---
Closes #19676File tree
75 files changed
+631
-350
lines changed- compiler/src/dotty/tools/dotc
- ast
- transform
- library/src/scala/annotation
- tests
- neg-macros
- annot-accessIndirect
- annot-crash
- annot-empty-result
- annot-error-annot
- annot-ill-abort
- annot-mod-class-add-top-method
- annot-mod-class-add-top-val
- annot-mod-top-method-add-top-method
- annot-mod-top-method-add-top-val
- annot-on-type
- annot-result-owner
- annot-suspend-cycle
- i18677-a
- i18677-b
- i18825
- i19676
- wrong-owner
- pos-macros
- annot-dependency-between-modules
- annot-in-object
- annot-suspend
- annot-then-inline
- i19537
- i19539
- macro-annot-with-companion
- run-macros
- annot-add-global-class
- annot-add-global-object
- annot-add-local-class
- annot-add-local-object
- annot-add-nested-class
- annot-add-nested-object
- annot-annot-order
- annot-bind
- annot-changeVal
- annot-concrete-class
- annot-export
- annot-gen2
- annot-generate
- annot-macro-main
- annot-memo
- annot-mod-class-add-def
- annot-mod-class-add-inner-class
- annot-mod-class-add-lazy-val
- annot-mod-class-add-local-class
- annot-mod-class-add-val
- annot-mod-class-add-var
- annot-mod-class-data
- annot-mod-class-equals
- annot-mod-class-mod-def
- annot-mod-class-mod-val
- annot-mod-class-override-def
- annot-mod-class-override-val
- annot-mod-class-unused-new-sym
- annot-result-order
- annot-simple-fib
- annot-unrollLast
- i18806
- i19676
- run/quotes-add-erased
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
75 files changed
+631
-350
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
Lines changed: 77 additions & 0 deletions
| 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 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
8 | 20 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | | - | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | | - | |
| 71 | + | |
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 76 | + | |
| 77 | + | |
91 | 78 | | |
92 | 79 | | |
93 | 80 | | |
| |||
113 | 100 | | |
114 | 101 | | |
115 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
116 | 144 | | |
| 145 | + | |
117 | 146 | | |
118 | 147 | | |
119 | 148 | | |
| |||
0 commit comments