[swift-dev] Pointers vs. References?

Jacob Bandes-Storch jtbandes at gmail.com
Mon Dec 14 13:43:43 CST 2015


I was thinking it might help some of the null-dereference issues if more
things were to be passed as references. Is there a particular reason to use
pointers instead? It seems there are several places which accept pointers
and assume they're not null, which isn't really safe.

(And, there's probably some work to be done adding `const` in a bunch of
places.)

Jacob

On Mon, Dec 14, 2015 at 11:34 AM, John McCall <rjmccall at apple.com> wrote:

> 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> 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
> 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/dd86996e/attachment.html>


More information about the swift-dev mailing list