Skip to content

compiler: add standalone locality directive analysis#2084

Closed
cpunion wants to merge 1 commit into
xgo-dev:mainfrom
cpunion:codex/locality-analysis
Closed

compiler: add standalone locality directive analysis#2084
cpunion wants to merge 1 commit into
xgo-dev:mainfrom
cpunion:codex/locality-analysis

Conversation

@cpunion

@cpunion cpunion commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a standalone source-analysis layer for LLGo package-variable locality directives.

  • internal/directive normalizes go:*, llgo:*, and //export comments without assigning feature semantics.
  • internal/locality defines the TLS/GLS source model, validates directive placement, groups variables by Go initialization unit, and prepares replayable initializer helpers.
  • The locality package does not import LLGo SSA, LLVM, the build cache, or the runtime.

This is a reviewable prerequisite for #2079. It intentionally does not connect the directives to the compiler pipeline or change generated code by itself; #2079 owns metadata integration, caching, lowering, runtime storage, and end-to-end tests.

Proposal: #2077

Why split this out

The previous #2079 diff mixed generic directive parsing, source semantics, compiler state, LLVM lowering, and runtime storage. Keeping source analysis in one independent package gives the compiler a small API and avoids moving unrelated go:*/llgo:* handling into a locality-specific implementation.

Semantics covered

  • package-level //llgo:tls and //llgo:gls declarations;
  • zero-valued, explicit, grouped, and multi-value initialization;
  • rejection on functions, local declarations, blank identifiers, conflicting ownership, and go:embed combinations;
  • one replay helper per indivisible Go initializer;
  • recursive/poisoned initialization metadata needed by the lowering layer; and
  • stable helper naming and idempotent preparation.

Tests

Run with GOMAXPROCS=2, GOMEMLIMIT=2GiB, GOFLAGS=-p=1, and a 15 GiB process-tree watchdog:

go test -cover ./internal/directive ./internal/locality -count=1
ok  github.com/goplus/llgo/internal/directive  coverage: 100.0%
ok  github.com/goplus/llgo/internal/locality   coverage: 100.0%

The commit was also checked out in an isolated worktree and passed independently of the remaining #2079 stack.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/locality-analysis branch from a260f03 to 4373348 Compare July 14, 2026 11:27
@cpunion

cpunion commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #2079. The directive parsing and locality source analysis remain part of the single TLS/GLS implementation PR so the feature can be reviewed and merged as one coherent change.

@cpunion cpunion closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant