[swift-dev] SIL: "unowned" the calling convention and "unowned" the variable ownership convention

Michael Gottesman mgottesman at apple.com
Tue Dec 29 17:18:55 CST 2015


One form of overloading that we currently have at the SIL level are the notions of the "unowned" calling convention and "unowned" the variable ownership convention.

For those who are unfamiliar with the unowned calling convention consider the following:

@tmp : $@convention(thin) (@owned Array<Double>, Array<Double>, Int, Int) -> Array<Double>

In this case the first parameter is passed in @owned (i.e. +1) and the second parameter is passed in as "unowned". Unowned is a form of +0 parameter passing that essentially means that the callee needs to take ownership of the value (ideally) before performing any side-effect having operations.

Overloading the term "unowned" in this way is confusing for new people at the SIL level. I would like to propose that we rename the unowned calling convention to something else (since unowned the variable ownership convention corresponds to a swift level concept that will be more difficult to change). Additionally no matter what we do, we should annotate "unowned" parameters and return values with an appropriate @"..." sigil to make it absolutely clear visually what the convention is.

In terms of names, I am partial to the name "immediate". My reasoning for using the term immediate is related to SGFContext in SILGen. In SILGen, there are three types of desired transfers defined by the DesiredTransfer enum.

  enum DesiredTransfer {                                                                                                                                                         
    PlusOne,                                                                                                                                                                     
    ImmediatePlusZero,                                                                                                                                                           
    GuaranteedPlusZero,                                                                                                                                                          
  };

PlusOne refers to @owned, GuaranteedPlusZero refers to @guaranteed, and if my memory is correct, ImmediatePlusZero refers to unowned. It seems natural to me to choose immediate for the name of the convention to match the terminology in SGFContext.

Comments, flames, etc?

Michael


More information about the swift-dev mailing list