[swift-dev] Optionals in swift-clang

Jordan Rose jordan_rose at apple.com
Tue Dec 8 20:03:57 CST 2015


Hi, Seth. I think you're getting Clang / swift-clang mixed up with swiftc / swift. Clang is not the Swift compiler; the Swift compiler lives in the "swift" repo. Swift depends on Clang for its interoperation with C and Objective-C.

A lot of the compiler encodes information about Optional, but most of it stems from ASTContext.h and ASTContext.cpp, which has dedicated entrypoints for getting Optional, Optional.None, and Optional.Some.

Hope this helps,
Jordan

> On Dec 8, 2015, at 17:59 , Seth Friedman via swift-dev <swift-dev at swift.org> wrote:
> 
> Hi all,
> 
> In Optional.swift in the stdlib, there's a comment that says "The compiler has special knowledge of Optional<Wrapped>, including the fact that it is an enum with cases named 'None' and 'Some'."
> 
> What I'm trying to understand is: If I wanted to implement the optional type from scratch, what would be the process I would go through? I've scoured the swift-clang project and can't seem to find any reference to optionals or even Swift explicitly. I discovered nullability attributes and am hypothesizing that an expression of something like "Type?" is somehow mapped to an attribute, but I'm really just stumbling around in the dark.
> 
> In terms of what I've tried, I've gone through a lot of the source in the swift-clang lib/Basic and lib/AST directories, and I've read through the "Clang CFE Internals Manual" on the Clang website.
> 
> Help is much appreciated!
> 
> Thanks in advance,
> Seth
>  _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151208/e8f3b78d/attachment.html>


More information about the swift-dev mailing list