@@ -150,7 +150,7 @@ Summarizing the above, the requirements are:
150
150
* Let macros introspect over declarations in known libraries for things like
151
151
subtype tests.
152
152
* Enable the Dart compiler to statically understand the library dependency
153
- graph of the program.
153
+ graph of the program before executing any macros .
154
154
* Allow macros to refer to declarations even in libraries that can't be run
155
155
in the macro execution environment.
156
156
@@ -232,10 +232,11 @@ In order to introspect over a declaration from a reflected import, the
232
232
` Identifier ` must first be resolved to a declaration. The [ macro introspection
233
233
API exposes] [ api ] methods to do that.
234
234
235
- ** TODO: Are these only available in certain phases? Can reflected imports be
236
- resolved in any phase? Once resolved, can they be deeply reflected over (i.e.
237
- walking the members of a class, etc.) or only used for things like subtype
238
- tests?**
235
+ The rules for introspection on identifiers from reflected imports are the same
236
+ as other identifiers a macro might encounter. This means you cannot navigate
237
+ to type declarations until after the types phase, and you cannot navigate to
238
+ other declarations until after the declarations phase. All type declarations
239
+ will also not be introspectable until the definitions phase.
239
240
240
241
** TODO: Would be good to show a concrete example of a macro using a reflected
241
242
import and introspecting over it in a subtype test.**
@@ -270,8 +271,13 @@ a distinct Dart "platform" and only it supports reflected imports. When
270
271
targeting any other execution environment, a Dart compiler reports a
271
272
compile-time error if it encounters a reflected import.
272
273
273
- ** TODO: What about unit tests for macros? They presumably run in the normal
274
- command line VM execution environment. Can they use reflected imports?**
274
+ ** TODO: How can we enforce this compile time restriction when macros
275
+ themselves are imported via normal imports? Do we need something like
276
+ https://github.com/dart-lang/language/pull/1831 ?**
277
+
278
+ This also means that macros cannot be _ unit tested_ . That is, you cannot
279
+ import, instantiate, and execute them as at runtime in the normal VM
280
+ environment (or any other normal runtime environment).
275
281
276
282
### Config-specific imports
277
283
@@ -289,7 +295,9 @@ configuration either.)
289
295
290
296
Thus, when determining what declarations are available for a reflected import,
291
297
** the compiler always uses the default URI for any config-specific imports or
292
- exports that it encounters.**
298
+ exports that it encounters.** . This may result in generating code which is not
299
+ actually compatible with all platforms, if the API differs across the
300
+ configuration specific imports.
293
301
294
302
** TODO: Consider making it a compile-time error for a reflected import to
295
303
having any config-specific imports, directly or transitively?**
0 commit comments