# 4.5.3-1.1 总体流程

类型检查的总体流程定义在`$GCROOT/compile/internal/types2/check.go`文件的方法`checkFiles`中，主体代码如下：

```go
func (check *Checker) checkFiles(files []*syntax.File) (err error) {
	check.initFiles(files)
	check.collectObjects()
	check.packageObjects()
	check.processDelayed(0) // incl. all functions
	check.initOrder()
	if !check.conf.DisableUnusedImportCheck {
		check.unusedImports()
	}
	check.recordUntyped()
	if check.Info != nil {
		sanitizeInfo(check.Info)
	}
	return
}
```

这里只保留了体现类型检查步骤的代码，删除的部分并不会影响我们对整个流程的理解。这几个方法包含了类型检查的所有重要内容，概括起来可以分为三个部分：&#x20;

1. 类型检查准备工作 \
   check.initFiles(files) 与 check.collectObjects()&#x20;
2. 类型检查 \
   check.packageObjects() 与 check.processDelayed(0)&#x20;
3. 确定全局变量初始化顺序 \
   check.initOrder()

我们接下来对各个部分进行分析。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gocompiler.shizhz.me/golang-bian-yi-qi-lei-xing-jian-cha/4.5.31.1-zong-ti-liu-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
