You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

7
+

17
8
18
-
Expanding a macro is always an additive operation:
19
-
Macros add new code,
20
-
but they never delete or modify existing code.
9
+
宏展开始终是一种加法操作:宏会添加新代码,但绝不会删除或修改现有代码。
21
10
22
-
Both the input to a macro and the output of macro expansion
23
-
are checked to ensure they're syntactically valid Swift code.
24
-
Likewise, the values you pass to a macro
25
-
and the values in code generated by a macro
26
-
are checked to ensure they have the correct types.
27
-
In addition,
28
-
if the macro's implementation encounters an error when expanding that macro,
29
-
the compiler treats this as a compilation error.
30
-
These guarantees make it easier to reason about code that uses macros,
31
-
and they make it easier to identify issues
32
-
like using a macro incorrectly
33
-
or a macro implementation that has a bug.
11
+
每个宏的输入和宏展开的输出都会被检查,以确保它们是语法上有效的 Swift 代码。同样,你传给宏的值以及宏生成的代码中的值也会被检查,以确保它们具有正确的类型。此外,如果宏的实现在扩展宏时遇到错误,编译器会将其视为编译错误。这些保证让使用了宏的代码更容易被推导,也更容易发现诸如宏使用不当或宏实现中的错误这样的问题。
34
12
35
-
Swift has two kinds of macros:
13
+
Swift 有两种宏:
36
14
37
-
-*Freestanding macros* appear on their own,
38
-
without being attached to a declaration.
15
+
-*独立宏*可单独出现,无需被附加到任何声明中。
39
16
40
-
-*Attached macros* modify the declaration that they're attached to.
17
+
-*附加宏*会修改它被附加到的声明。
41
18
42
-
You call attached and freestanding macros slightly differently,
43
-
but they both follow the same model for macro expansion,
44
-
and you implement them both using the same approach.
45
-
The following sections describe both kinds of macros in more detail.
0 commit comments