Skip to content

checklocks: fix generics Origin fact lookup#12443

Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tamird:checklocks-generic
Jan 7, 2026
Merged

checklocks: fix generics Origin fact lookup#12443
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tamird:checklocks-generic

Conversation

@tamird
Copy link
Contributor

@tamird tamird commented Jan 6, 2026

checklocks attaches lock facts to the declaration objects produced by
go/types, but SSA analysis of generic code can observe instantiated
*types.Var/*types.Func objects instead. Importing facts from those
instantiated objects fails, which causes spurious inference warnings
("may require checklocks annotation...") and can miss expected
checklocksfail reports.

Fix this by falling back to Origin() when importing lock guard and
function facts, and by normalizing inference observation keys to the
origin object so inference uses the same fact identity as export.

Add regression coverage for generic methods and functions, including a
cross-package generics.

Fixes #10372.
Fixes #11671.
Closes #11740.

@tamird
Copy link
Contributor Author

tamird commented Jan 6, 2026

@EtiennePerot would you mind having a look?

@tamird tamird force-pushed the checklocks-generic branch from 68bde13 to 15bbe2c Compare January 6, 2026 21:49
checklocks attaches lock facts to the declaration objects produced by
go/types, but SSA analysis of generic code can observe instantiated
`*types.Var/*types.Func` objects instead. Importing facts from those
instantiated objects fails, which causes spurious inference warnings
("may require checklocks annotation...") and can miss expected
checklocksfail reports.

Fix this by falling back to Origin() when importing lock guard and
function facts, and by normalizing inference observation keys to the
origin object so inference uses the same fact identity as export.

Add regression coverage for generic methods and functions, including a
cross-package generics.
@tamird tamird force-pushed the checklocks-generic branch from 15bbe2c to 9fc2083 Compare January 6, 2026 21:57
@tamird
Copy link
Contributor Author

tamird commented Jan 6, 2026

@kakkoyun FYI

copybara-service bot pushed a commit that referenced this pull request Jan 7, 2026
checklocks attaches lock facts to the declaration objects produced by
go/types, but SSA analysis of generic code can observe instantiated
`*types.Var/*types.Func` objects instead. Importing facts from those
instantiated objects fails, which causes spurious inference warnings
("may require checklocks annotation...") and can miss expected
checklocksfail reports.

Fix this by falling back to Origin() when importing lock guard and
function facts, and by normalizing inference observation keys to the
origin object so inference uses the same fact identity as export.

Add regression coverage for generic methods and functions, including a
cross-package generics.

Fixes #10372.
Fixes #11671.
Closes #11740.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12443 from tamird:checklocks-generic 9fc2083
PiperOrigin-RevId: 853130453
Copy link

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for taking care of it!

copybara-service bot pushed a commit that referenced this pull request Jan 7, 2026
checklocks attaches lock facts to the declaration objects produced by
go/types, but SSA analysis of generic code can observe instantiated
`*types.Var/*types.Func` objects instead. Importing facts from those
instantiated objects fails, which causes spurious inference warnings
("may require checklocks annotation...") and can miss expected
checklocksfail reports.

Fix this by falling back to Origin() when importing lock guard and
function facts, and by normalizing inference observation keys to the
origin object so inference uses the same fact identity as export.

Add regression coverage for generic methods and functions, including a
cross-package generics.

Fixes #10372.
Fixes #11671.
Closes #11740.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12443 from tamird:checklocks-generic 9fc2083
PiperOrigin-RevId: 853130453
@copybara-service copybara-service bot merged commit 8b481a1 into google:master Jan 7, 2026
3 checks passed
@tamird tamird deleted the checklocks-generic branch January 7, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools/checklocks: Generics support [checklocks] Annotations ignored on generic structs

4 participants