Commits
Chris Lattner committed fe16d538cde
In -enable-top-level-definite-init mode, emit a "mark_function_escape" instruction
for func decls that capture globals defined in the current file. For example, for:
var x : Int
func foo() {
print(x)
}
x = 15
We now silgen to:
sil internal @top_level_code : $() -> () {
bb0:
%0 = global_addr #x : $*Int64 // user: %1
%1 = mark_uninitialized %0 : $*Int64 // users: %7, %2
mark_function_escape %1 : $*Int64
// function_ref swift.Int64._convertFromBuiltinIntegerLiteral (swift.Int64.metatype)(val : Builtin.Int128) -> swift.Int64
%3 = function_ref @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %6
%4 = metatype $Int64.metatype // user: %6
%5 = integer_literal $Builtin.Int128, 15 // user: %6
%6 = apply [transparent] %3(%5, %4) : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %7
assign %6 to %1 : $*Int64
%8 = tuple () // user: %9
return %8 : $()
}
which will allow definite initialization to diagnose the error.
Note that we don't currently handle uses in constructors, like:
class frank {
constructor() {
print(x)
}
}
... because the capture list is only stored for FuncDecls, not for AbstractFunction's. It should be hoisted up at some point.
Swift SVN r8188