# Unknown attributes should be a warning (not an error)

**URL:** <https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493>\
**Category:** Pitches\
**Tags:** attributes\
**Created:** [December 9, 2019, 12:13pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493 "2019-12-09T12:13:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![broadway\_lamb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/broadway_lamb/32/665_2.png) [@broadway\_lamb](https://forums.swift.org/u/broadway_lamb)\
**Post date:** [December 9, 2019, 12:13pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/1 "2019-12-09T12:13:58Z")

</div>

There are some private attributes like `@inline(__always)`, `@_specialize`, `@_exported` etc, that are considered unstable (i. e. they may go away any time), but nonetheless are quite important in some use cases (like the [CryptoSwift](https://github.com/krzyzanowskim/CryptoSwift) library, which, according to its maintainer, is really slow without all those private attributes).

At the same time, it is unclear whether those attributes will ever make it through Swift Evolution, as their use cases are too narrow to be worth a proposal. Also, there's this "I want to write cool things in Swift right now, not wait 5 years until a language feature is maybe de-underscored" factor.

Those library authors that make use of those attributes are unintentionally putting their users in danger: any time their app may stop compiling after upgrading to a new Xcode version just because some dependency used those underscored attributes, and some of them went away in that new Xcode version.

Can the core team consider making unknown attributes a warning rather than an error? In this case, if, say, `@inline(__always)` is removed, the libraries that make use of it won't break. In other words, can we adopt the same behavior as [C++11 attributes](https://en.cppreference.com/w/cpp/language/attributes)?

---

<div class="post-metadata">

**Author:** ![cukr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cukr/32/889_2.png) [@cukr](https://forums.swift.org/u/cukr)\
**Post date:** [December 9, 2019, 12:38pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/2 "2019-12-09T12:38:13Z")

</div>

on the other hand if someone writes `@_dontFormatMyHardDrive` and then it gets removed from the language, I would like for it to be a build error, instead of the app running and my hard drive being formatted

---

<div class="post-metadata">

**Author:** ![broadway\_lamb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/broadway_lamb/32/665_2.png) [@broadway\_lamb](https://forums.swift.org/u/broadway_lamb)\
**Post date:** [December 9, 2019, 12:48pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/3 "2019-12-09T12:48:17Z")

</div>

Your example is super artificial. I can't think of any **existing** built-in underscore attribute such that its removal changes the semantic meaning of a program. Will it break compilation? Yes, maybe (e. g. `@_exported`). But not semantics. If adding or removing it changed semantics, it would be a keyword.

(We're not looking at property wrappers, obviously.)

---

<div class="post-metadata">

**Author:** ![cukr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cukr/32/889_2.png) [@cukr](https://forums.swift.org/u/cukr)\
**Post date:** [December 9, 2019, 1:02pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/4 "2019-12-09T13:02:24Z")

</div>

> [@broadway\_lamb](#):
>
> I can't think of any **existing** built-in underscore attribute such that its removal changes the semantic meaning of a program.

```swift
@_swift_native_objc_runtime_base(Foo)
class Bar { }

let x: AnyObject = Bar()
let selector = Selector("doTheThing")
if x.responds(to: selector) {
    x.performSelector(onMainThread: selector, with: nil, waitUntilDone: true)
}

```

It will change the semantics of the code if `Foo` implements method "doTheThing"

---

<div class="post-metadata">

**Author:** ![broadway\_lamb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/broadway_lamb/32/665_2.png) [@broadway\_lamb](https://forums.swift.org/u/broadway_lamb)\
**Post date:** [December 9, 2019, 1:07pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/5 "2019-12-09T13:07:54Z")

</div>

Oh.

Well, I was wrong then.

---

<div class="post-metadata">

**Author:** ![cukr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cukr/32/889_2.png) [@cukr](https://forums.swift.org/u/cukr)\
**Post date:** [December 9, 2019, 1:26pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/6 "2019-12-09T13:26:34Z")

</div>

But I do agree, my example is super artificial and almost always the result would be either code not compiling at all, or still working well

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [December 9, 2019, 9:55pm UTC](https://forums.swift.org/t/unknown-attributes-should-be-a-warning-not-an-error/31493/7 "2019-12-09T21:55:57Z")

</div>

> [@broadway\_lamb](#):
>
> There are some private attributes like `@inline(__always)` , `@_specialize` , `@_exported` etc, that are considered unstable (i. e. they may go away any time), but nonetheless are quite important in some use cases (like the [CryptoSwift](https://github.com/krzyzanowskim/CryptoSwift) library, which, according to its maintainer, is really slow without all those private attributes).

> [@broadway\_lamb](#):
>
> Can the core team consider making unknown attributes a warning rather than an error? In this case, if, say, `@inline(__always)` is removed, the libraries that make use of it won't break.

When it comes to performance, `@inline(__always)` and `@_specialize` should not be needed anymore. `@inlinable` should cover any performance‐related uses of either of them. And if it doesn’t, that fact should be reported as a bug.

If `@inline(__always)` is being used [for security reasons](https://swiftrocks.com/the-forbidden-inline-attribute-in-swift.html)—which it isn’t reliable for in the first place—then you really do not want it to go ignored and open a security hole.

If `@_exported` is being used, demoting it from error to warning won’t solve anything, since with the re‐export missing, you’ll hit a sudden wall of undefined symbol errors.

> [@broadway\_lamb](#):
>
> At the same time, it is unclear whether those attributes will ever make it through Swift Evolution, as their use cases are too narrow to be worth a proposal.

Their use cases are not too narrow. As noted above, `@inline(__always)`, `@_specialize` and their relatives already led to the fully supported `@inlinable`. And the problem space of `@_exported` is undergoing active development to transform it into a more robust model that can be declared stable:

> [@Update on implementation-only imports](https://forums.swift.org/t/update-on-implementation-only-imports/26996):
>
> After the long discussion on the [previous thread](https://forums.swift.org/t/exported-and-fixing-import-visibility/9415/), @John_McCall and I went away to go prototype the main new feature: implementation-only imports. (I'm staying away from "private imports" to avoid the implications of access control for now, as well as the other experimental "private imports" feature that's in support of [dynamic method replacement](https://forums.swift.org/t/dynamic-method-replacement/16619).) We've been doing this work on the master and 5.1 branches of the compiler so that some Apple projects can live on it for a while to make sure (1) it w…

* * *

> [@broadway\_lamb](#):
>
> Those library authors that make use of those attributes are unintentionally putting their users in danger:

They are doing so intentionally. Those attributes are not in any official documentation. If a developer even knows about them, they either discovered them as experimental features buried in the compiler’s source code, or received them as a suggestion from someone else who had. When these attributes pop up in conversation around here, it is always with a disclaimer that they are not finished yet and are a use‐at‐your‐own‐risk sort of thing. And for the most part that is true of the rest of the web as well.
