<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 18, 2016, at 9:18 AM, Seth Friedman via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">Exactly. I'm just trying to understand how someone would go about adding new syntax to the language<br class=""></div></blockquote><div><br class=""></div><div>It’s a bunch of steps… roughly:</div><div><br class=""></div><div>1) Teach the parser to recognize your syntax in one of the parseExpr* routines</div><div>2) Add a new node kind to include/swift/AST/ExprNodes.def and add its implementation in include/swift/AST/Expr.h. If you build, you’ll get warnings or errors for all of the places in the compiler that need to be updated, which includes...</div><div>3) Add type checking support (lib/Sema/CS*.cpp), mapping to a completely type-checked expression</div><div>4) Add SILGen support (lib/SILGen/SILGenRValue.cpp) to map your expression down to SIL</div><div><br class=""></div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Jan 18, 2016 at 9:13 AM Svein Halvor Halvorsen &lt;<a href="mailto:svein.h@lvor.halvorsen.cc" class="">svein.h@lvor.halvorsen.cc</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">So you want a completely new kind of literal, that is neither a string, integer, float, etc.<div class="">Kinda like the special array and dictionary literals?</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-01-18 18:10 GMT+01:00 Seth Friedman <span dir="ltr" class="">&lt;<a href="mailto:sethfri@gmail.com" target="_blank" class="">sethfri@gmail.com</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sure, but this is a completely arbitrary, simple example designed to illustrate how to add new syntax to Swift. Conforming to IntegerLiteralConvertible would defeat the point of the exercise.<br class=""><br class="">Thanks,<br class="">Seth <br class=""><div class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Jan 18, 2016 at 8:55 AM Svein Halvor Halvorsen &lt;<a href="mailto:svein.h@lvor.halvorsen.cc" target="_blank" class="">svein.h@lvor.halvorsen.cc</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Can't you just make your SuperInt conform to IntergerLiteralConvertible and initialise it like so:<div class=""><br class=""></div><div class="">let superIntExample: SuperInt = 100</div><div class=""><br class=""></div><div class="">sv.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-01-18 1:13 GMT+01:00 Seth Friedman via swift-dev <span dir="ltr" class="">&lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Created&nbsp;<a href="https://bugs.swift.org/browse/SR-569" target="_blank" class="">SR-569</a>&nbsp;to track this<div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">Seth</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Jan 10, 2016 at 4:18 PM, Seth Friedman <span dir="ltr" class="">&lt;<a href="mailto:sethfri@gmail.com" target="_blank" class="">sethfri@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="white-space:pre-wrap" class="">Changing the subject of this thread since it's now an entirely different question than what I originally asked. Hopefully this will result in better visibility in getting an answer as well.<br class=""><br class="">Thanks,<br class="">Seth</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Jan 10, 2016 at 4:16 PM Seth Friedman &lt;<a href="mailto:sethfri@gmail.com" target="_blank" class="">sethfri@gmail.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Jordan!<br class=""><br class="">Here's a specific flow I'm interested in understanding. Note that this is just a wild example that would help me better understand parts of the compiler I'm interested in rather than any sort of proposal for the language.<br class=""><br class="">Let's say I have a type called SuperInt that has some cool integer operations that would be applicable and useful to everyone writing Swift. It's a given that this makes sense to be in the Swift language, and people are going to be using it so often that it makes sense to create a new literal syntax for this type. I'd like users to be able to instantiate a SuperInt with the following:<br class=""><br class="">let superIntExample = %^100^%<br class=""><br class="">Crazy syntax for a crazy example, but I wanted to make sure it's not something that's already in Swift. In this example, my SuperInt would be instantiated with a value of 100.<br class=""><br class="">I'd like to know the parts of the Swift compiler I would need to understand and change to implement this new type with its new syntax.<br class=""><br class="">I really this question requires a lengthy answer, but I think it would make a great start to a Swift internals manual (which I agree with you would be a fantastic idea).<br class=""><br class="">Anyone's help would be much appreciated!<br class=""><br class="">Thanks,<br class="">Seth<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Dec 18, 2015 at 5:25 PM Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" target="_blank" class="">jordan_rose@apple.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi, Seth. Sorry for not getting back to you sooner! I don't think we have anything exactly like this, but there's <i class="">sort</i>&nbsp;of a sequence diagram in Chris and Joe's talk at the LLVM conference, "<a href="https://youtu.be/Ntj8ab-5cvE" target="_blank" class="">Swift's High-Level IR</a>". I'd say it looks something like this:</div><div class=""><br class=""></div><div class="">1. Parsing</div><div class="">2. Semantic analysis, including type-checking</div><div class="">3. SIL generation</div><div class="">4. Mandatory SIL passes</div><div class="">5. SIL optimization</div><div class="">6. LLVM IR generation</div><div class="">7. LLVM optimization</div><div class="">8. LLVM output (usually including machine code generation and writing to a .o file)</div><div class=""><br class=""></div><div class="">…with the last two handled pretty much completely by&nbsp;<a href="http://llvm.org/" target="_blank" class="">LLVM</a>&nbsp;itself, and not customized by Swift.</div><div class=""><br class=""></div><div class="">We probably ought to have something like Clang's "<a href="http://clang.llvm.org/docs/InternalsManual.html" target="_blank" class="">Internals</a>" manual (hopefully better), which lays out the major concepts in each library. As it is we have various concepts that are documented very well, either in docs/ or in header comments, and others which are just arcane knowledge in the heads of the implementers. This is not a good thing.</div><div class=""><br class=""></div><div class="">The "<a href="https://swift.org/contributing/" target="_blank" class="">Contributing</a>" page on the website lists a handful of ways to get involved; another one we're still bringing up is issues with the "StarterBug" label in JIRA. These are intended to be bugs that a newcomer could use as a goal-oriented way to learn about one part of the project.</div><div class=""><br class=""></div><div class="">Of course, we're happy to answer any specific questions you might have (and this list is probably the right place for them). It's the general ones that are hard. :-)</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">Jordan</div></div><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 2:36, Seth Friedman &lt;<a href="mailto:sethfri@gmail.com" target="_blank" class="">sethfri@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div style="white-space:pre-wrap" class="">Thanks Jordan!<br class=""><br class="">Another question if anyone has some time: I'm really interested in contributing to the project, but given that I don't have a ton of experience with compilers, I'm having a really hard time following the flow of the program. I understand that the high level flow is lexing, parsing, sema, and building the AST. However, tracing through the actual functions in the compiler prove much more difficult due to the amount of indirection/metaprogramming.<br class=""><br class="">Are there any sort of sequence diagrams that I haven't found yet? If anyone could let me know of any good resources you know of, that would be great. I'm sure this would also be of use to people in my boat that want to help but don't know how to start.<br class=""><br class="">Thanks,<br class="">Seth</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Dec 8, 2015 at 9:04 PM Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" target="_blank" class="">jordan_rose@apple.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">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.</div><div class=""><br class=""></div><div class="">A <i class="">lot</i>&nbsp;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.</div><div class=""><br class=""></div><div class="">Hope this helps,</div><div class="">Jordan</div><br class=""><div class=""><blockquote type="cite" class=""></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 17:59 , Seth Friedman via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class=""></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="white-space:pre-wrap" class="">Hi all,<br class=""><br class="">In Optional.swift in the stdlib, there's a comment that says "The compiler has special knowledge of Optional&lt;Wrapped&gt;, including the fact that it is an enum with cases named 'None' and 'Some'."<br class=""><br class="">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.<br class=""><br class="">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.<br class=""><br class="">Help is much appreciated!<br class=""><br class="">Thanks in advance,<br class="">Seth</div>
</div></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSBL6HRSS2hzpFojqZUT85ho4HsE-2FB0XLWrcqkyvQBO5xufppQ8uPgxEwiKwgl62G3z1r-2BUiBJC1BXFFOiAgFN8sYiuSJIgxPeG9oDjBYl-2BjYeGhsvoyyj8qwRtpVhGMN6onwcfLODiw-2B-2FRXFdKLIXbuUSf1FU50IqzQBipBXcb37O1Np08nQCz4e4XNzuhG5HY-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div><br class=""></div></blockquote></div></blockquote></div></blockquote></div><span class=""><font color="#888888" class=""><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class="">Seth Friedman<div class=""><i class="">Software Development Engineer II</i></div><div class=""><i class=""><a href="http://amazon.com" class="">Amazon.com</a></i></div></div></div></div></div>
</font></span></div>
<br class="">_______________________________________________<br class="">
swift-dev mailing list<br class="">
<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</blockquote></div>
</div></div></blockquote></div><br class=""></div>
</blockquote></div>
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></body></html>