From 58fec203a2431c3ca6a3f9467d07d132876abfff Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 7 Feb 2020 13:21:28 -0500 Subject: [PATCH] internal/lsp/cache: don't type check types.Unsafe Recent test runs exposed that we are racing to types.Unsafe, as a result of parallel type checking. Example: https://storage.googleapis.com/go-build-log/494dd1dd/linux-amd64-race_c978961e.log We shouldn't have to type check unsafe, so we can return early instead. Change-Id: I20143dbfb07925d85d7342b93360bdda1c45e4aa Reviewed-on: https://go-review.googlesource.com/c/tools/+/218497 Reviewed-by: Rebecca Stambler --- internal/lsp/cache/check.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 9b3c0fdb131..ff90c2efa19 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -325,6 +325,9 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc // Use the default type information for the unsafe package. if pkg.pkgPath == "unsafe" { pkg.types = types.Unsafe + // Don't type check Unsafe: it's unnecessary, and doing so exposes a data + // race to Unsafe.completed. + return pkg, nil } else if len(files) == 0 { // not the unsafe package, no parsed files return nil, errors.Errorf("no parsed files for package %s, expected: %s, errors: %v, list errors: %v", pkg.pkgPath, pkg.compiledGoFiles, actualErrors, rawErrors) } else {