[swift-dev] Pointers vs. References?

John McCall rjmccall at apple.com
Mon Dec 14 13:34:58 CST 2015


> On Dec 12, 2015, at 4:20 PM, Michael Gottesman via swift-dev <swift-dev at swift.org> wrote:
> In general, we have not been particularly disciplined in this regard. I would suggest following what is being done locally in the file you are modifying, i.e. FuncDecl */TypeChecker & as per the LLVM style guide.

There are common rules at work here that govern most situations.  We almost always pass around objects that are part of the language representation as either pointers (e.g. AST/SIL/LLVM nodes) or values (e.g. Type, SILDeclRef); pretty much everything else is passed around as a reference, especially classes that manage the creation or manipulation of the language representation (e.g. IRGenModule, TypeChecker).

The biggest grey area is for those parts of the language representation that are either globally or contextually singleton, e.g. ASTContext and SILFunction; these are almost always stored as references.

John.

> 
> Michael
> 
>> On Dec 12, 2015, at 3:15 PM, Jacob Bandes-Storch via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>> 
>> I've noticed a mix of pointers (FuncDecl*) and references (TypeChecker&) in the C++ codebase. Is there a particular reason for this? Perhaps a style guide?
>> 
>> Jacob
>>  _______________________________________________
>> swift-dev mailing list
>> swift-dev at swift.org <mailto:swift-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-dev
> 
> 
> _______________________________________________
> 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/20151214/8c16bf5a/attachment.html>


More information about the swift-dev mailing list