Skip to content

Commit b1e9584

Browse files
authored
clean up macro examples and README.md, remove run.dart script (#3582)
- Delete run.dart script and update the README.md to indicate you can just pass `--enable-experiment=macros`. - Break up `user_main.dart` into separate scripts for each macro example, which allows you to run the ones that do work, and also keeps the example apps more targetted. These were only combined into one previously to make it easier to run them through `run.dart`. - Update the observable example so it is runnable. - Update the data class example to create the unnamed constructor instead of one called `gen`.
1 parent fa5a895 commit b1e9584

File tree

11 files changed

+100
-287
lines changed

11 files changed

+100
-287
lines changed

working/macros/example/README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
**DISCLAIMER**: All code in this package is experimental and should be treated
2-
as such.
3-
4-
This package some example macros (under `lib`), as well as some utilities to try
5-
actually running those examples.
2+
as such. The examples are unstable and may or may not work at any given time,
3+
depending on the implementation status.
64

75
## Setup
86

97
Your SDK will need to match roughly the commit pinned in the pubspec.yaml file
108
of this package (see the `ref` lines). Otherwise you will get a kernel version
119
mismatch.
1210

11+
## Examples
12+
13+
The example macros live under `lib/` and there are programs using them under
14+
`bin/`. To try and run an example, you need to enable the `macros` experiment,
15+
`dart --enable-experiment=macros <script>`, but the implementations do not yet
16+
support all the examples here so you should expect errors.
17+
1318
## Benchmarks
1419

1520
There is a basic benchmark at `benchmark/simple.dart`. You can run this tool
@@ -19,12 +24,3 @@ environment (compiler).
1924

2025
This benchmark uses a synthetic program, and only benchmarks the overhead of
2126
running the macro itself, and the communication to and from the host program.
22-
23-
## Examples
24-
25-
There is an example program at `bin/user_main.dart`. This _cannot_ be directly
26-
executed but you can compile and execute it with the `bin/run.dart` script.
27-
28-
**NOTE**: This is not meant to be a representative example of how a script using
29-
macros would be compiled and ran in the real world, but it does allow you to
30-
execute the program.

working/macros/example/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ analyzer:
77
# TODO: remove these when the analyzer supports macros enough to run them
88
- bin/checks_main.dart
99
- bin/injectable_main.dart
10-
- bin/user_main.dart
1110
- bin/json_serializable_main.dart
1211
- bin/observable_main.dart
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:macro_proposal/auto_dispose.dart';
6+
7+
void main() {
8+
var state = MyState(a: ADisposable(), b: BDisposable(), c: 'hello world');
9+
state.dispose();
10+
}
11+
12+
@AutoDispose()
13+
class MyState extends State {
14+
final ADisposable a;
15+
final ADisposable? a2;
16+
final BDisposable b;
17+
final String c;
18+
19+
MyState({required this.a, this.a2, required this.b, required this.c});
20+
21+
@override
22+
String toString() => 'MyState!';
23+
}
24+
25+
class State {
26+
void dispose() {
27+
print('disposing of $this');
28+
}
29+
}
30+
31+
class ADisposable implements Disposable {
32+
void dispose() {
33+
print('disposing of ADisposable');
34+
}
35+
}
36+
37+
class BDisposable implements Disposable {
38+
void dispose() {
39+
print('disposing of BDisposable');
40+
}
41+
}

working/macros/example/bin/checks_main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
@ChecksExtensions([Person])
26
library;
37

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:macro_proposal/data_class.dart';
6+
7+
void main() {
8+
var joe = User(age: 25, name: 'Joe', username: 'joe1234');
9+
print(joe);
10+
11+
var phoenix = joe.copyWith(name: 'Phoenix', age: 23);
12+
print(phoenix);
13+
}
14+
15+
@DataClass()
16+
class User {
17+
final int age;
18+
final String name;
19+
final String username;
20+
}
21+
22+
@DataClass()
23+
class Manager extends User {
24+
final List<User> reports;
25+
}

working/macros/example/bin/injectable_main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'package:macro_proposal/injectable.dart';
26

37
void main() {

working/macros/example/bin/observable_main.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'package:macro_proposal/observable.dart';
26

37
void main() {
@@ -16,6 +20,6 @@ class ObservableUser {
1620
ObservableUser({
1721
required int age,
1822
required String name,
19-
}) : _age = age,
20-
_name = name;
23+
}) : _age = age,
24+
_name = name;
2125
}

working/macros/example/bin/run.dart

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)