Commit Graph

4 Commits

Author SHA1 Message Date
Allan Shortlidge
164ac421d6 Sema: Lift restriction preventing use of #_hasSymbol on non-Darwin platforms.
An early approach to codegen for `#_hasSymbol` relied on the Darwin platfom SDK, but now that the feature lowers directly to NULL checks in LLVM IR a platform restriction is no longer needed.

However, the tests for `#_hasSymbol` remain unsupported on Windows since that OS does not support weak linking.
2022-11-30 14:58:28 -08:00
Allan Shortlidge
64e8a0334d Sema: Diagnose if #_hasSymbol as unsupported on non-Darwin targets. 2022-10-08 00:09:34 -07:00
Allan Shortlidge
ba46170b54 Implement type checking for the #_hasSymbol directive. The directive takes an expression which must resolve at compile time to a single concrete declaration. There are a few kinds of expressions which we intend to accept:
- Unapplied functions: `if #_hasSymbol(foo(_:))`
- Member references: `if #_hasSymbol(a.x)`
- `.self` expressions on static metatypes: `if #_hasSymbol(SomeEnum.self)`
- Dot syntax call expressions with unapplied functions: `if #_hasSymbol(SomeType.init(_:)`

Additionally, we diagnose when the concretely referenced declaration is not weak linked since this likely indicates that the programmer misidentified the declaration they wish to check or the build is not configured in a way such that the check will be meaningful.

Resolves rdar://99826340
2022-09-19 10:40:37 -07:00
Allan Shortlidge
f5f1d3c028 AST: Parse #_hasSymbol
Introduce the compiler directive `#_hasSymbol` which will be used to detect whether weakly linked symbols are present at runtime. It is intended for use in combination with `@_weakLinked import` or `-weak-link-at-target`.

```
if #_hasSymbol(foo(_:)) {
  foo(42)
}
```

Parsing only; SILGen is coming in a later commit.

Resolves rdar://99342017
2022-09-08 17:15:29 -07:00