Julian Voigt
Julian Voigt

Reputation: 41

Where is the defer statement implemented?

I would like to know how and why the defer-Statement works and where it is implemented(in Compiler Source Code).

I found the package about parsing the defer-Statement and building it in the syntax-tree

But I'm interestetd in the actual exection of defer at runtime. My guess is, that it's somewhere inside the "src/runtime"

Upvotes: 3

Views: 298

Answers (1)

RayfenWindspear
RayfenWindspear

Reputation: 6284

Begin reading here https://github.com/golang/go/blob/d089a6c7187f1ff85277515405ec6c641588a7ff/src/runtime/panic.go#L70

You can also search the repository for the term "deferreturn" to find more results.

Assembly for defer jumps here https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L550

Upvotes: 5

Related Questions