[swift-users] Tuple of two or more instances to withExtendedLifetime

Jens Persson jens at bitcycle.com
Wed Dec 13 15:41:44 CST 2017


Ok, thanks!

On Wed, Dec 13, 2017 at 10:20 PM, Andrew Trick <atrick at apple.com> wrote:

> Yes, withExtendedLifetime is a generic API that guarantees the lifetime of
> any non-trivial value. i.e. if the tuple contains a reference, the lifetime
> of that reference will be extended.
>
> That said, there is a theoretical bug in the optimizer that you will be
> much more likely to hit in practice if you pass a tuple to this API. I
> still think it’s extremely unlikely that the  code will be miscompiled
> though, and I’m sure it will be fixed shortly ;)
>
> https://bugs.swift.org/browse/SR-6608: DeadCodeElimination removes
> fix_lifetime
>
> -Andy
>
> > On Dec 13, 2017, at 10:05 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> >
> > Good question and good thought! I believe the answer is yes, this will
> work as intended, but I'd like to get someone more versed in SIL than me to
> verify that. Andy?
> >
> > Jordan
> >
> >
> >> On Dec 13, 2017, at 01:28, Jens Persson via swift-users <
> swift-users at swift.org> wrote:
> >>
> >> There are no restrictions on the type of the first argument to
> withExtendedLiftetime, even though it makes sense only for reference types.
> >>
> >> So both the below variants will compile, and my question is if the
> first one will work as expected (extending the lifetime of both a and b) or
> if the second variant must be used instead.
> >>
> >> 1:
> >> withExtendedLifetime((a, b)) {
> >>    ...
> >> }
> >>
> >> 2:
> >> withExtendedLifetime(a) {
> >>    withExtendedLifetime(b) {
> >>        ...
> >>    }
> >> }
> >>
> >> /Jens
> >>
> >> _______________________________________________
> >> swift-users mailing list
> >> swift-users at swift.org
> >> https://lists.swift.org/mailman/listinfo/swift-users
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171213/3300503d/attachment.html>


More information about the swift-users mailing list