<div dir="ltr">I reported it 5/16 in bug reporter. Possibly that was the wrong DB?<div><br></div><div><a href="https://bugreport.apple.com/web/?problemID=26535526">https://bugreport.apple.com/web/?problemID=26535526</a><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 28, 2017 at 8:45 AM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Aug 27, 2017, at 10:57 AM, Edward Connell via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
><br>
</span><span class="">> import Foundation<br>
><br>
> class A {<br>
> var counter = 0 {<br>
> // didSet { onSet("counter") } // no leak<br>
> didSet { onSet() } // huge leak<br>
> }<br>
><br>
> var properties = ["counter" : 0]<br>
> func onSet(_ name: String = #function) {<br>
> properties[name]! += 1<br>
> }<br>
> }<br>
><br>
> var myclass = A()<br>
><br>
> for i in 0..<10000000 {<br>
> myclass.counter = i<br>
> }<br>
><br>
> print(myclass.properties["<wbr>counter"]!)<br>
<br>
</span>The only code generation difference I see, if I modify your didSet to make both calls is that the compiler treats #function as a UTF-16 literal, whereas "counter" is recognized as an ASCII literal:<br>
<br>
// A.counter.didset<br>
sil hidden @_T03foo1AC7counterSifW : $@convention(method) (Int, @guaranteed A) -> () {<br>
// %0 // user: %2<br>
// %1 // users: %19, %12, %11, %4, %3<br>
bb0(%0 : $Int, %1 : $A):<br>
debug_value %0 : $Int, let, name "oldValue", argno 1 // id: %2<br>
debug_value %1 : $A, let, name "self", argno 2 // id: %3<br>
%4 = class_method %1 : $A, #A.onSet!1 : (A) -> (String) -> (), $@convention(method) (@owned String, @guaranteed A) -> () // user: %11<br>
%5 = string_literal utf8 "counter" // user: %10<br>
%6 = integer_literal $Builtin.Word, 7 // user: %10<br>
%7 = integer_literal $Builtin.Int1, -1 // user: %10<br>
%8 = metatype $@thin String.Type // user: %10<br>
// function_ref String.init(_<wbr>builtinStringLiteral:<wbr>utf8CodeUnitCount:isASCII:)<br>
%9 = function_ref @_T0S2SBp21_<wbr>builtinStringLiteral_<wbr>Bw17utf8CodeUnitCountBi1_<wbr>7isASCIItcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %10<br>
%10 = apply %9(%5, %6, %7, %8) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %11<br>
%11 = apply %4(%10, %1) : $@convention(method) (@owned String, @guaranteed A) -> ()<br>
%12 = class_method %1 : $A, #A.onSet!1 : (A) -> (String) -> (), $@convention(method) (@owned String, @guaranteed A) -> () // user: %19<br>
%13 = string_literal utf16 "counter" // user: %18<br>
%14 = integer_literal $Builtin.Word, 7 // user: %18<br>
%15 = integer_literal $Builtin.Int1, -1<br>
%16 = metatype $@thin String.Type // user: %18<br>
// function_ref String.init(_<wbr>builtinUTF16StringLiteral:<wbr>utf16CodeUnitCount:)<br>
%17 = function_ref @_T0S2SBp26_<wbr>builtinUTF16StringLiteral_<wbr>Bw18utf16CodeUnitCounttcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, @thin String.Type) -> @owned String // user: %18<br>
%18 = apply %17(%13, %14, %16) : $@convention(method) (Builtin.RawPointer, Builtin.Word, @thin String.Type) -> @owned String // user: %19<br>
%19 = apply %12(%18, %1) : $@convention(method) (@owned String, @guaranteed A) -> ()<br>
%20 = tuple () // user: %21<br>
return %20 : $() // id: %21<br>
} // end sil function '_T03foo1AC7counterSifW'<br>
<br>
Michael, could there be a leak in the implementation of String(_<wbr>builtinUTF16StringLiteral:<wbr>utf16CodeUnitCount:)? The SIL at first glance looks balanced here.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Joe<br>
<br>
</font></span></blockquote></div><br></div>