Skip to content

Comments

[compiler]internal symbols#9762

Draft
witemple-msft wants to merge 13 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/internal-symbols
Draft

[compiler]internal symbols#9762
witemple-msft wants to merge 13 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/internal-symbols

Conversation

@witemple-msft
Copy link
Member

@witemple-msft witemple-msft commented Feb 20, 2026

This PR enables libraries to define internal symbols that cannot be referenced from outside the same project scope.

internal can apply to any declaration except namespace. Internality is a property of symbols, not of types. A Type that is declared internal can be used from a different package, but can't be referred to by name. This allows you to use an alias to publicly expose an internal declaration:

internal model X {}

// Totally fine -- the model itself isn't internal, only the _symbol_ `X` is.
alias Public = X;

Resolution logic for symbols declared with internal is:

  • Resolution is allowed if the source location is in the compiler stdlib or is synthetic (programmatic through checker.resolveTypeReference or otherwise synthetic).
  • Resolution is allowed if the source location is a library, and the target symbol was declared within that same library.
  • Resolution is allowed if the source location is the user project, and the target symbol was declared within the user project.
  • Resolution is otherwise disallowed.

Notes:

  • To preserve backwards compatibility, internal is allowed as the name of a model property, since it is allowed as one now. The logic for this also allows extern to be a model property name, which isn't currently allowed.

Implementation:

  • Refactors parser a bit to handle modifiers on all declarations.
  • Adds SymbolFlags.Internal, which binds to a symbol if the corresponding declaration has ModifierFlags.Internal.
  • Access control is enforced in resolveTypeReferenceSymInternal when resolving a type reference. Access control must pass for any referenced symbol.

@microsoft-github-policy-service microsoft-github-policy-service bot added compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates labels Feb 20, 2026
@github-actions
Copy link
Contributor

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/compiler
Show changes

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/compiler@9762

commit: dae3275

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants