Skip to content

Commit 1a407a5

Browse files
committed
wip: usableFromInline
1 parent 0651f97 commit 1a407a5

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

swift-6-beta.docc/ReferenceManual/Attributes.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,33 +2353,26 @@ struct ArrayBuilder {
23532353

23542354
### usableFromInline
23552355

2356-
Apply this attribute to a
2357-
function, method, computed property, subscript,
2358-
initializer, or deinitializer declaration
2359-
to allow that symbol to be used in inlinable code
2360-
that's defined in the same module as the declaration.
2361-
The declaration must have the `internal` access-level modifier.
2362-
A structure or class marked `usableFromInline`
2363-
can use only types that are public or `usableFromInline` for its properties.
2364-
An enumeration marked `usableFromInline`
2365-
can use only types that are public or `usableFromInline`
2366-
for the raw values and associated values of its cases.
2367-
2368-
Like the `public` access-level modifier,
2369-
this attribute
2370-
exposes the declaration as part of the module's public interface.
2371-
Unlike `public`,
2372-
the compiler doesn't allow declarations marked with `usableFromInline`
2373-
to be referenced by name in code outside the module,
2374-
even though the declaration's symbol is exported.
2375-
However, code outside the module might still be able
2376-
to interact with the declaration's symbol by using runtime behavior.
2377-
2378-
Declarations marked with the `inlinable` attribute
2379-
are implicitly usable from inlinable code.
2380-
Although either `inlinable` or `usableFromInline`
2381-
can be applied to `internal` declarations,
2382-
applying both attributes is an error.
2356+
将此属性应用于函数、方法、计算属性、下标、构造器或析构器声明,
2357+
以允许该符号在与声明位于同一模块中定义的内联代码中使用。
2358+
声明必须具有 `internal` 访问级别修饰符。
2359+
标记为 `usableFromInline` 的结构或类
2360+
只能对其属性使用公共类型或 `usableFromInline` 类型。
2361+
标记为 `usableFromInline` 的枚举
2362+
只能对其枚举成员的原始值和关联值使用公共类型或 `usableFromInline` 类型。
2363+
2364+
`public` 访问级别修饰符一样,
2365+
这个属性将声明暴露为模块公共接口的一部分。
2366+
`public` 不同,
2367+
编译器不允许在模块外的代码中按名称引用标记为 `usableFromInline` 的声明,
2368+
即使声明的符号已被导出。
2369+
然而,模块外的代码仍然可以通过使用运行时行为与声明的符号进行交互。
2370+
2371+
标记为 `inlinable` 特性的声明
2372+
可以隐式地从可内联代码中使用。
2373+
虽然 `inlinable``usableFromInline`
2374+
都可以应用于 `internal` 声明,
2375+
但同时应用这两个特性是错误的。
23832376

23842377
<!--
23852378
- test: `usableFromInline-and-inlinable-is-redundant`

0 commit comments

Comments
 (0)