Skip to content

vyperlang/vyper / skills

vyper-compiler

Verified

Vyper smart contract compiler internals. Use when working on the Vyper compiler codebase — compilation pipeline, Venom IR, semantic analysis, code generation, testing, or contributing. Triggers on vyper compiler development, Venom passes, AST/semantics changes, codegen work, or test writing.

FileKindSize
SKILL.mdskill md4.4 KB
codegen.mdmarkdown1.1 KB
contributing.mdmarkdown7.8 KB
semantics.mdmarkdown2.3 KB
testing.mdmarkdown1.6 KB
venom.mdmarkdown2.0 KB

semantics.md

View on GitHub
# Semantics & Frontend

Type checking, validation, and semantic analysis of Vyper AST.

Primary reference: [vyper/semantics/README.md](../vyper/semantics/README.md) — full control flow, design, examples.

## Pipeline

```
Source → pre_parser → Python AST → Vyper AST → semantic analysis → annotated AST
```

### AST Phase (`vyper/ast/`)

See [vyper/ast/README.md](../vyper/ast/README.md).

- `pre_parser.py`: Vyper source → parseable Python (substitutes `struct`/`interface` → `class`, etc.)
- `grammar.lark`: Lark grammar definition (for reference/making sure we adhere to a bnf spec)
- `nodes.py`: Vyper AST node classes (use `__slots__`)
- `parse.py` / `utils.py`: `parse_to_ast()` — main entry

### Semantic Analysis Phase (`vyper/semantics/`)

Entry: `vyper.semantics.analyze_module()`

Four steps:
1. **Pre-typecheck** (`analysis/pre_typecheck.py`): fold constant expressions
2. **Namespace init** (`namespace.py`): populate builtins, types, env vars
3. **Module validation** (`analysis/module.py`): storage vars, user types, imports, function sigs
4. **Local validation** (`analysis/local.py`): per-function type checking and annotation

## Type System (`vyper/semantics/types/`)

Type classes live in `vyper/semantics/types/`. Convention: classes end in `T` (e.g. `IntegerT`, `ModuleT`).
Base classes in `bases.py`. Browse the directory for the full set — file names map to type categories
(primitives, bytestrings, subscriptable, user-defined, function, module).

Type inference (aka type synthesis) is very limited and only for expressions: `(x: uint8) + 1` has type `uint8`, this is done by `_ExprAnalyser().get_possible_types_from_node`.
Type checking is done by `ExprVisitor`.
Those are not fully decoupled however.

## Namespace

`Namespace` (`namespace.py`) is a dict subclass with scoping via context manager:

```python
with namespace.enter_scope():
    namespace["x"] = some_type
# x no longer exists here
```

Scopes: builtin → module → local → (for/if blocks).

## Analysis

Analysis and validation logic lives in `vyper/semantics/analysis/`. Key files:
- `module.py` — module-level validation (storage, types, imports)
- `local.py` — `FunctionNodeVisitor`, per-function validation
- `annotation.py` — type annotation of expressions

Browse the directory for the full set. Also see `data_locations.py` and `environment.py` at the `semantics/` level.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall