Copilot instructions
.github/instructions/Compiler.instructions.mdCopilot instructions
Quality
99/100
Scores the file, not the repository.Length
525 words
17 headings · 3 code blocksRepository
21k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.12345# Roslyn Compiler Instructions for AI Coding Agents67## Architecture Overview89Roslyn follows a **layered compiler architecture**:10- **Lexer → Parser → Syntax Trees → Semantic Analysis → Lowering/Rewriting → Symbol Tables → Emit**11- Core abstraction: `Compilation` is immutable and reusable. Create new compilations via `AddSyntaxTrees()`, `RemoveSyntaxTrees()`, `ReplaceSyntaxTree()` for incremental changes12- **Internal vs Public APIs**: Use `InternalSyntax` namespace for performance-critical parsing; `Microsoft.CodeAnalysis` for public consumption1314### Key Directories15- `src/Compilers/Core/Portable/` - Language-agnostic compiler infrastructure16- `src/Compilers/CSharp/Portable/` - C# compiler implementation17- `src/Compilers/VisualBasic/Portable/` - VB compiler implementation18- `src/Compilers/Server/` - `VBCSCompiler` build server19- `src/Dependencies/` - High-performance collections (`PooledObjects`, `Threading`)20- `src/ExpressionEvaluator/` - Debugger expression evaluation (uses special `LexerMode.DebuggerSyntax`)21- `src/Tools/` - Compiler tooling (BuildBoss, format tools, analyzers)2223### Essential Files for Context24- `src/Compilers/CSharp/Portable/Errors/ErrorCode.cs` - All C# compiler error codes25- `src/Compilers/CSharp/Portable/Errors/MessageID.cs` - Language feature version gating26- `src/Compilers/CSharp/Portable/Syntax/Syntax.xml` - Syntax tree node definitions (generated code source)27- `src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml` - Bound tree node definitions (generated code source)28- `docs/wiki/Roslyn-Overview.md` - Architecture deep-dive2930## Code Generation3132Several core data structures are generated from XML definitions — **never edit the generated `.cs` or `.vb` files directly**:33- **Syntax trees**: `src/Compilers/CSharp/Portable/Syntax/Syntax.xml`34- **Bound trees**: `src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml`35- After modifying these XML files, regenerate and build:36```bash37 dotnet run --file eng/generate-compiler-code.cs38 dotnet build src/Compilers/{CSharp,VisualBasic}/Portable # choose the project matching the C# or VB syntax you changed39```4041## Conventions4243- **MEF is not used in the compiler layer.** `ExportLanguageService` / `ImportingConstructor` and the IDE service model are IDE-layer concepts — ignore them here.44- **Null checks**: validate internal-API preconditions with `Debug.Assert(...)` (a violated internal precondition may NRE in release); validate public APIs with explicit null checking when appropriate, throwing a dedicated exception with a localized string.45- **Immutability** is via `Compilation` (`AddSyntaxTrees`/`RemoveSyntaxTrees`/`ReplaceSyntaxTree`), not the workspace `Document`/`Solution` model.4647## Essential Patterns4849### Memory Management50- **Avoid LINQ in hot paths** - use manual enumeration or `struct` enumerators51- **Avoid `foreach` over collections without struct enumerators**52- **Use object pools extensively** - see patterns in `src/Dependencies/PooledObjects/`53- **Prefer `Debug.Assert()` over exceptions** for internal validation5455## Build & Test Workflows5657### Essential Build Commands5859```powershell60# Full build (use VS Code tasks when available)61./build.sh6263# Build specific components64dotnet build Compilers.slnf # Compiler-only build65dotnet build src/Compilers/CSharp/csc/AnyCpu/ # C# compiler6667# Generate compiler code after changes68dotnet run --file eng/generate-compiler-code.cs69```7071## Debugger Integration7273**Expression Evaluator** uses special parsing modes:74- `LexerMode.DebuggerSyntax` for expression evaluation75- `IsInFieldKeywordContext` flag for context-aware parsing76- `ConsumeFullText` parameter for complete expression parsing7778## MSBuild Integration7980Compiler tasks are in `src/Compilers/Core/MSBuildTask/`:81- `Csc.cs` - C# compiler task82- `Vbc.cs` - VB compiler task83- `ManagedCompiler.cs` - Base compiler task functionality8485## Performance Considerations86871. **Lexer/Parser optimizations**: Use `InternalSyntax` types for performance-critical code882. **Immutable data structures**: Roslyn heavily uses immutable collections and copy-on-write semantics893. **Caching**: `Compilation` objects cache semantic information - reuse when possible904. **Threading**: Most compiler operations are thread-safe through immutability9192## Symbol Resolution9394Navigate the symbol hierarchy:95```cs96var compilation = CreateCompilation(source);97var globalNamespace = compilation.GlobalNamespace;98var typeSymbol = globalNamespace.GetTypeMembers("MyClass").Single();99var methodSymbol = typeSymbol.GetMembers("MyMethod").Single();100```101102Symbol equality is complex due to generics and substitution - always test with multiple generic scenarios.103
Also in dotnet/roslyn
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/IDE.instructions.md · 21k | Copilot instructions | stylearch | 70/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/Razor.instructions.md · 21k | Copilot instructions | buildstyletypesdo-not+1 | 67/100 | 3 days ago | |
| dotnet/roslynAGENTS.md · 21k | AGENTS.md | buildagent-behaviour | 43/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 2 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 74k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago | |
| bagisto/bagisto.github/copilot-instructions.md · 28k | Copilot instructions | setupbuildteststyle+5 | 97/100 | 3 days ago |
