Skip to content

[compiler]internal symbols#9762

Merged
witemple-msft merged 26 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/internal-symbols
Mar 2, 2026
Merged

[compiler]internal symbols#9762
witemple-msft merged 26 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/internal-symbols

Conversation

@witemple-msft
Copy link
Copy Markdown
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
Copy Markdown
Contributor

github-actions Bot commented Feb 20, 2026

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/tspd
Show changes

@typespec/compiler - feature ✏️

Added experimental support for internal modifiers on type declarations. Any type except namespace can be declared internal. An internal symbol can only be accessed from within the same package where it was declared.

@typespec/tspd - internal ✏️

Updated documentation generation to ignore items tagged internal.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 20, 2026

Open in StackBlitz

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

commit: df16015

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Feb 20, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@witemple-msft witemple-msft marked this pull request as ready for review February 24, 2026 20:14
@microsoft-github-policy-service microsoft-github-policy-service Bot added the tspd Issues for the tspd tool label Feb 24, 2026
Comment thread packages/compiler/test/formatter/formatter.test.ts
Comment thread packages/compiler/src/server/tmlanguage.ts Outdated
Comment thread packages/compiler/src/core/parser.ts Outdated
Comment thread packages/compiler/src/core/messages.ts
Comment thread packages/compiler/src/core/messages.ts Outdated
Copy link
Copy Markdown
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

Looks good, just if we can easily also mark compiler internal decorators internal via the checker it would be good

@witemple-msft witemple-msft added the int:azure-specs Run integration tests against azure-rest-api-specs label Mar 2, 2026
@witemple-msft witemple-msft added this pull request to the merge queue Mar 2, 2026
Merged via the queue into microsoft:main with commit 9bca04b Mar 2, 2026
29 checks passed
@witemple-msft witemple-msft deleted the witemple-msft/internal-symbols branch March 2, 2026 18:03
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 int:azure-specs Run integration tests against azure-rest-api-specs meta:website TypeSpec.io updates tspd Issues for the tspd tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants