Upgrade to Pro — share decks privately, control downloads, hide ads and more …

static lazy varの挙動を追ってみた

static lazy varの挙動を追ってみた

noppefoxwolf

May 31, 2018
Tweet

More Decks by noppefoxwolf

Other Decks in Technology

Transcript

  1. USZ4XJGUƊƑǜDžǡǙDž lazy var value: Int = { preconditionFailure() }() Ԛ௹߄с⇜ƍǭȃǧǜƹƵMB[ZWBSƊ࿆࿽żƮŶƋ

    ƊaսೆభƎƸDžǑǏżƮƋઋƋżŶƋůƊŰƮb ơƂ/FWFSƊْżŶƋƊƵ൐ƲŽƎ࿆࿽ƊŰƮb ! !OPQQFGPYXPMG  
  2. TUBUJD⴬ඔƑMB[ZWBS UVUPSJBMTXJGU class Class { static lazy var value: Int

    = { preconditionFailure() }() } Class.value = 1 ! !OPQQFGPYXPMG  
  3. $ swiftc tutorial001.swift tutorial001.swift:2:10: error: 'lazy' must not be used

    on an already-lazy global static lazy var value: Int = { preconditionFailure() }() ^~~~~ MB[ZNVTUOPUCFVTFEPOBOBMSFBEZMB[Z HMPCBM wHMPCBM⴬ඔƒ࠻ƎMB[ZƃŮƬaMB[ZŧƬƍŧƫ ! x ! !OPQQFGPYXPMG  
  4. UVUPSJBMTXJGU class Class { static var value: Int = {

    preconditionFailure() }() } Class.value = 1 MB[ZƵຓźƉljȉǧƺȁƥӮۿĆ ! !OPQQFGPYXPMG  
  5. Ệ㗈 YYYYYTXJGU class Class { static var xxxxx: Int =

    { preconditionFailure() }() } ⴬ඔƵƲŮƭƧżŲYYYYƎźƉ4*-Ƶԛ৯źƉƢƮ 4XJGU*OUFSNFEJBUF-BOHVBHF4XJGUƑᇏᾇ࿽∽ ! !OPQQFGPYXPMG  
  6. // static Class.xxxxx.setter sil hidden [transparent] @_T05xxxxx5ClassCAASivsZ : $@convention(method) (Int,

    @thick Class.Type) -> () { // %0 // users: %8, %2 // %1 // user: %3 bb0(%0 : $Int, %1 : $@thick Class.Type): debug_value %0 : $Int, let, name "value", argno 1 // id: %2 debug_value %1 : $@thick Class.Type, let, name "self", argno 2 // id: %3 // function_ref Class.xxxxx.unsafeMutableAddressor %4 = function_ref @_T05xxxxx5ClassCAASivau : $@convention(thin) () -> Builtin.RawPointer // user: %5 %5 = apply %4() : $@convention(thin) () -> Builtin.RawPointer // user: %6 %6 = pointer_to_address %5 : $Builtin.RawPointer to [strict] $*Int // user: %7 %7 = begin_access [modify] [dynamic] %6 : $*Int // users: %9, %8 assign %0 to %7 : $*Int // id: %8 end_access %7 : $*Int // id: %9 %10 = tuple () // user: %11 return %10 : $() // id: %11 } // end sil function '_T05xxxxx5ClassCAASivsZ' %4 ~ %5 ॳظԽ %6 ~ %7 ୅ೖ ! !OPQQFGPYXPMG  
  7. %4 = function_ref @_T05xxxxx5ClassCAASivau : $@convention(thin) () -> Builtin.RawPointer //

    user: %5 %5 = apply %4() : $@convention(thin) () -> Builtin.RawPointer // user: %6 GVODUJPO@SFGTJMGVODUJPOOBNFTJMUZQF4*-倔ඔ ƛƑҕᅶƵቔӮ @5YYYYY$MBTT$""4JWBVč䴙ƆƉŧŲƋ QSFDPOEJUJPO'BJMVSFĎƑҕᅶቔӮ BQQMZƊ⻎ྛ ! !OPQQFGPYXPMG  
  8. 'lazy' must not be used on an already- lazy global

    MB[Z䵐࿼۬ₑǭȃǧǜƹƑMB[ZƋƒ↎ũၩ໅ ! !OPQQFGPYXPMG