RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/Copilot instructions/dotnet/runtime

Copilot instructions

.github/instructions/native.instructions.md
Copilot instructions

Quality

76/100

Scores the file, not the repository.

Length

765 words

12 headings · 0 code blocks

Repository

18k

— · pushed 0 days ago

Last changed

3 days ago

First indexed 3 days ago.
dotnet/runtime/.github/instructions/native.instructions.mdRawGitHub
1---
2applyTo: "**/*.c,**/*.cc,**/*.cpp,**/*.cxx,**/*.h,**/*.hpp,**/*.inc,**/*.S,**/*.s,**/*.asm"
3---
4 
5# Native code (C/C++/asm) & interop
6 
7Conventions for native runtime code (CoreCLR VM, JIT, `src/native`, Mono native). Also apply
8`conventions`, `tests` for test changes, and `core-runtime` for CoreCLR and native host changes.
9For JIT specifics see `jit`; for networking interop see `system-net-interop`.
10 
11## Correctness & Safety
12 
13### Error Handling & Assertions
14 
15- **Handle OOM with exceptions or fail-fast, never asserts.** Use `ThrowOutOfMemory` or `EEPOLICY_HANDLE_FATAL_ERROR`, not asserts. In interpreter loops, use `nothrow new` and check for null.
16- **Use `_ASSERTE(!"message")` for unreachable native paths.** Keep native assertion guidance in native code rather than applying managed exception patterns.
17- **Guard native size and offset arithmetic against overflow.** Validate multiplication and addition used for allocation sizes, buffer indexes, and pointer offsets before performing the operation. Prefer patterns and helpers that are correct by construction rather than checking an already-overflowed result.
18 
19### JIT-Specific Correctness
20 
21- **JIT lowering must not double-lower nodes.** Never call `LowerNode` on an already-lowered node. Return newly created nodes for the caller to lower. Constant folding belongs in import/morph, not lowering.
22- **Mark collectible ALC test methods `NoInlining`.** Methods that touch collectible assembly load contexts must be `[MethodImpl(MethodImplOptions.NoInlining)]` to prevent the JIT from keeping references alive.
23 
24## Performance & Allocations
25 
26### Code Structure for Performance
27 
28- **Separate hot data from rarely-used data in runtime structures.** Keep frequently accessed data inline; move rarely-used data (GCInfo, DebugInfo) to separate structures.
29- **Compute constant data at compile time, not execution time.** In interpreter and similar hot paths, pre-compute metadata lookups and type checks during the compilation phase.
30 
31## Code Style & Formatting
32 
33- **Prefer table-driven approaches over excessive case statements.** For hardware intrinsics and pattern-heavy code, use lookup tables (`AuxiliaryJitType`, `SpecialCodeGen` flags) instead of many explicit case entries.
34- **Order struct fields to minimize padding.** In C/C++ struct definitions, order fields by size (pointers first) to reduce padding.
35- **Run `jit-format` before pushing JIT changes.** JIT code must pass `jit-format` to avoid immediately failing CI. Run it with `python3 src/coreclr/scripts/jitformat.py -r . -o <os> -a <arch>` in the repo root. This should be done automatically when authoring JIT code and prior to pushing.
36 
37## Platform & Cross-Platform
38 
39- **Use correct platform/feature defines.** Use `TARGET_*`/`HOST_*` defines rather than compiler-provided defines (`__wasm__`). Use `HOST_*` for build machine code, `TARGET_*` for target platform. Use `PORTABILITY_ASSERT` for unimplemented platform code.
40 
41## Native Code & Interop
42 
43### C++ Style
44 
45- **Don't use `auto` in the runtime C++ codebase.** Use explicit types. Exception: unspeakable types like lambdas.
46- **Use `nullptr`, `void*`, and native C++ types over legacy aliases.** Prefer `nullptr` over `NULL`, `void*` over `LPVOID`. Use `WCHAR` (not `wchar_t`) in Windows host code. Use `.inc` suffix for multiply-included files.
47- **Match `#endif` comments to `#ifdef` exactly.** Add comments on `#else`/`#endif` for non-trivial blocks. Consistent brace placement and four-space indentation.
48- **Prefer `static_cast` over C-style casts.** C-style casts are more permissive than needed and can silently degrade to `reinterpret_cast`.
49 
50### Runtime & VM Patterns
51 
52- **Use correct VM contracts and QCall patterns.** QCalls that may throw need `BEGIN_QCALL`/`END_QCALL`. Simple QCalls use `QCALL_CONTRACT_NO_GC_TRANSITION`. All VM methods need `STANDARD_VM_CONTRACT` or `WRAPPER_NO_CONTRACT`.
53- **Append new GC-EE interface methods last.** Preserve vtable slot ordering by adding methods only at the end of the interface.
54- **Keep GC protection correct around managed references.** Ensure all GC references are `GCPROTECT`-ed before GC-triggering calls. After GC-triggering calls, use `ObjectFromHandle(handle)` for a fresh reference.
55- **Avoid dynamic allocation on fatal error paths.** Use stack-allocated buffers. Use simple synchronization (Interlocked with spin-wait) instead of Monitor/lock.
56- **Avoid thread-local objects with destructors in CoreCLR.** Destruction order is arbitrary. Tie lifetime to the CoreCLR Thread object. Prefer `PLATFORM_THREAD_LOCAL` from minipal over C++ `thread_local` in perf-critical paths.
57- **Use `SET_UNALIGNED` macros for potentially unaligned writes.** In code generation stubs, use `SET_UNALIGNED_32/64` rather than direct pointer dereferencing.
58- **Zero-initialize arrays and buffers that may be partially used.** Zero-init allocated arrays whose elements have destructors. Zero-init EH tables, C arrays, and similar structures.
59- **Add static asserts for hardcoded structural offsets.** When using hardcoded offsets to access struct fields (especially in assembly), add static asserts to verify them.
60- **Use minipal for new platform abstractions.** Use minipal (new) instead of PAL (legacy) for platform abstraction in new CoreCLR code. Use `ALTERNATE_ENTRY` (not `LOCAL_LABEL`) for assembly labels called from outside their function.
61- **Use `JITDUMP` and `LOG` macros, not `printf`.** In JIT code use `JITDUMP`. In CoreCLR VM use `LOG()`/`LOGGING` defines. Do not use `printf` or `Console.WriteLine` in production native code.
62 
63### P/Invoke & Marshalling
64 
65- **Prefer 4-byte `BOOL` for native interop marshalling.** Use `UnmanagedType.Bool`. Verify P/Invoke return types match native signatures exactly—mismatches may work on 64-bit but fail on 32-bit/WASM.
66 

Commands it names

  • python3 src/coreclr/scripts/jitformat.py -r . -o <os> -a <arch>

Sections

  • Native code (C/C++/asm) & interop
  • Correctness & Safety
  • Error Handling & Assertions
  • JIT-Specific Correctness
  • Performance & Allocations
  • Code Structure for Performance
  • Code Style & Formatting
  • Platform & Cross-Platform
  • Native Code & Interop
  • C++ Style
  • Runtime & VM Patterns
  • P/Invoke & Marshalling

What it covers

lint-formatcode-stylearchitectureperformance

Stack — with the evidence

csharp

(1.00)

dotnet

(1.00)

node

(0.95)

eslint

(0.70)

typescript

(0.60)

github-actions

(0.60)

javascript

(0.50)

Glob targeting

  • **/*.c
  • **/*.cc
  • **/*.cpp
  • **/*.cxx
  • **/*.h
  • **/*.hpp
  • **/*.inc
  • **/*.S
  • **/*.s
  • **/*.asm

Format

Copilot instructions

Two layers: one always-on repo file, plus optional glob-scoped instruction files. Lives under .github/ rather than the repo root, which is the tell that it is aimed at the GitHub platform surface as much as the editor.

What the corpus says about it

Repository

Owner
dotnet
Language
—
License
—
Archived
no

All configs in this repo

Also in dotnet/runtime

Diff this repo’s formats

One 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?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
dotnet/runtime.github/instructions/system-net-interop.instructions.md · 18kCopilot instructionscsharpdotnet+5stylearchperformance56/1003 days ago
dotnet/runtime.github/instructions/extensions-logging.instructions.md · 18kCopilot instructionscsharpdotnet+5securityperformance44/1003 days ago
dotnet/runtime.github/instructions/system-net-security.instructions.md · 18kCopilot instructionscsharpdotnet+5securityperformancedeployment48/1003 days ago
dotnet/runtime.github/copilot-instructions.md · 18kCopilot instructionscsharpdotnet+5buildteststylearch+278/1003 days ago
dotnet/runtime.github/instructions/cdac.instructions.md · 18kCopilot instructionscsharpdotnet+5typesgitapidocs52/1003 days ago
dotnet/runtime.github/instructions/compression.instructions.md · 18kCopilot instructionscsharpdotnet+5testlint-formatstylesecurity+160/1003 days ago
dotnet/runtime.github/instructions/conventions.instructions.md · 18kCopilot instructionscsharpdotnet+5stylearchagent-behaviourdocs56/1003 days ago
dotnet/runtime.github/instructions/core-runtime.instructions.md · 18kCopilot instructionscsharpdotnet+5styleperformance43/1003 days ago
dotnet/runtime.github/instructions/csharp.instructions.md · 18kCopilot instructionscsharpdotnet+5lint-formatstylearchsecurity+359/1003 days ago
dotnet/runtime.github/instructions/extensions-caching.instructions.md · 18kCopilot instructionscsharpdotnet+5styleperformanceagent-behaviour48/1003 days ago
dotnet/runtime.github/instructions/extensions-common.instructions.md · 18kCopilot instructionscsharpdotnet+5styledependencies48/1003 days ago
dotnet/runtime.github/instructions/extensions-configuration.instructions.md · 18kCopilot instructionscsharpdotnet+5no sections44/1003 days ago
dotnet/runtime.github/instructions/extensions-di.instructions.md · 18kCopilot instructionscsharpdotnet+5teststyletesting-strategy52/1003 days ago
dotnet/runtime.github/instructions/extensions-hosting.instructions.md · 18kCopilot instructionscsharpdotnet+5teststyleagent-behaviour52/1003 days ago
dotnet/runtime.github/instructions/extensions-options.instructions.md · 18kCopilot instructionscsharpdotnet+5style48/1003 days ago
dotnet/runtime.github/instructions/jit.instructions.md · 18kCopilot instructionscsharpdotnet+5buildgit29/1003 days ago
dotnet/runtime.github/instructions/system-net-common.instructions.md · 18kCopilot instructionscsharpdotnet+5styledependenciesapi48/1003 days ago
dotnet/runtime.github/instructions/system-net-http.instructions.md · 18kCopilot instructionscsharpdotnet+5styleperformance52/1003 days ago
dotnet/runtime.github/instructions/system-net-quic.instructions.md · 18kCopilot instructionscsharpdotnet+5teststyleperformance56/1003 days ago
dotnet/runtime.github/instructions/system-net-sockets.instructions.md · 18kCopilot instructionscsharpdotnet+5styleagent-behaviour48/1003 days ago
Diff against .github/instructions/system-net-interop.instructions.md Diff against .github/instructions/extensions-logging.instructions.md Diff against .github/instructions/system-net-security.instructions.md Diff against .github/copilot-instructions.md Diff against .github/instructions/cdac.instructions.md Diff against .github/instructions/compression.instructions.md Diff against .github/instructions/conventions.instructions.md Diff against .github/instructions/core-runtime.instructions.md Diff against .github/instructions/csharp.instructions.md Diff against .github/instructions/extensions-caching.instructions.md Diff against .github/instructions/extensions-common.instructions.md Diff against .github/instructions/extensions-configuration.instructions.md Diff against .github/instructions/extensions-di.instructions.md Diff against .github/instructions/extensions-hosting.instructions.md Diff against .github/instructions/extensions-options.instructions.md Diff against .github/instructions/jit.instructions.md Diff against .github/instructions/system-net-common.instructions.md Diff against .github/instructions/system-net-http.instructions.md Diff against .github/instructions/system-net-quic.instructions.md Diff against .github/instructions/system-net-sockets.instructions.md

Similar configs

Same format, overlapping stack, ranked by quality.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63Copilot instructionstypescriptreact+7buildlint-formatstylearch+4100/1003 days ago
louislam/uptime-kuma.github/copilot-instructions.md · 90kCopilot instructionstypescriptjavascript+10setupbuildtestlint-format+9100/1003 days ago
HerringtonDarkholme/megarepo.github/copilot-instructions.md · 17Copilot instructionsnodejavascriptsetupbuildtestlint-format+7100/1003 days ago
dotnet/roslyn.github/instructions/Compiler.instructions.md · 21kCopilot instructionscsharpdotnet+1buildteststylearch+399/1003 days ago
JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31kCopilot instructionstypescriptnode+7buildlint-formatstylearch+397/1002 days ago
dotnet/roslyn.github/copilot-instructions.md · 21kCopilot instructionscsharpdotnet+1buildteststylearch+397/1003 days ago
bagisto/bagisto.github/copilot-instructions.md · 28kCopilot instructionsphplaravel+8setupbuildteststyle+597/1003 days ago
darkmatter/nixmac.github/copilot-instructions.md · 24Copilot instructionstypescriptrust+14setupbuildtestlint-format+896/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack