compiler: assume external functions don't let pointers escape
Assume any external function won't let pointers live longer than the call itself. This is true in the vast majority of cases (apparently everywhere currently) but might not always be true. TODO: add a //go:noescape (or maybe //go:escape) to handle this, instead of this assumption.
Этот коммит содержится в:
родитель
772c6486ab
коммит
2a5c331516
1 изменённых файлов: 10 добавлений и 0 удалений
|
@ -219,6 +219,16 @@ func (c *Compiler) doesEscape(value llvm.Value) bool {
|
||||||
// Call only escapes when the (pointer) parameter is not marked
|
// Call only escapes when the (pointer) parameter is not marked
|
||||||
// "nocapture". This flag means that the parameter does not escape
|
// "nocapture". This flag means that the parameter does not escape
|
||||||
// the give function.
|
// the give function.
|
||||||
|
if use.CalledValue().IsAFunction() != nilValue {
|
||||||
|
if use.CalledValue().IsDeclaration() {
|
||||||
|
// Kind of dirty: assume external functions don't let
|
||||||
|
// pointers escape.
|
||||||
|
// TODO: introduce //go:noescape that sets the 'nocapture'
|
||||||
|
// flag on each input parameter.
|
||||||
|
println("declaration:", use.CalledValue().Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
if !c.hasFlag(use, value, "nocapture") {
|
if !c.hasFlag(use, value, "nocapture") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче