[POC] Enable feature via directive#9886
Closed
timotheeguerin wants to merge 2 commits into
Closed
Conversation
commit: |
Contributor
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
Member
|
Few thoughts:
|
Member
Author
|
For 2 isn't it what alternative A ## is? Open to a different combo though |
Collaborator
|
You can try these changes here
|
Member
Author
|
Design meeting:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature Flags via Directives
Playground demo
Status
Proof of concept — code is 100% AI-generated and unreviewed. Demo only via playground/pkg.
Problem
When introducing new TypeSpec language features or behavior changes, there is no mechanism for users to incrementally opt in (or opt out) at the spec level. Today, features are either globally on or globally off based on the compiler version. This makes it difficult to:
Proposal
Allow users to toggle named features using a directive-like statement in their TypeSpec source:
Semantics
"internal-modifier").#enableopts in;#disableopts out.Open Questions
1. Is a directive the right syntax?
The
#prefix is currently used for node-targeting directives (#suppress,#deprecated). Reusing#for statement-level directives that don't target a specific node may be confusing.Alternative A: Double
##for statement-level directivesPros: Visually distinguishes statement-level directives from node-targeting ones.
Cons: Subtle difference (
#vs##) may be easy to miss.Alternative B: Keyword-based syntax
Pros: Reads naturally, consistent with other statement keywords.
Cons:
enable/disableare not currently reserved keywords — reserving them would be a (limited) breaking change.Alternative C: Keyword with explicit value
Pros: Single keyword to reserve, explicit on/off value.
Cons: More verbose,
on/offare not established patterns in TypeSpec.Alternative D: Configuration in tspconfig.yaml
Pros: No new syntax needed, leverages existing configuration infrastructure. Clear separation between compiler configuration and spec authoring.
Cons: Cannot vary per-file or per-namespace — applies to the entire project. Less visible to someone reading the spec. Doesn't compose well if different parts of a project need different flags. Additionally,
tspconfig.yamlcurrently serves as a build/output configuration rather than a project-level concept — there is no notion of a "tspconfig project" today, a single project may use multiple tspconfigs, and libraries don't read a tspconfig at all. Using it for feature flags would either require rethinking the role of tspconfig or accepting that flags wouldn't propagate through library boundaries.2. Scope boundary
3. Feature lifecycle
4. Compiler integration
Next Steps
internal-modifier)