Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
69b4a13
Start implementing the type checker
osa1 Sep 26, 2025
4e5342a
Port Scheme and Pred types
osa1 Sep 27, 2025
f48e97e
Implement PredSet, document why we don't use a HashSet for preds
osa1 Sep 28, 2025
118b99f
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Sep 28, 2025
ddf0712
Start implementing instantiating type schemes
osa1 Sep 28, 2025
06b0438
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Sep 29, 2025
73e725c
Fix import
osa1 Sep 30, 2025
e7cdd5d
Add LocalId type, implement substQVars
osa1 Sep 30, 2025
dd91d4f
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Sep 30, 2025
d1926e6
Implement UVars and RVars as discussed
osa1 Oct 1, 2025
5339f98
Update AST tc ty fields
osa1 Oct 1, 2025
9f63721
Merge branch 'main' into type_checking
osa1 Oct 1, 2025
a067c69
Merge branch 'main' into type_checking
osa1 Oct 1, 2025
b94659a
ToDoc impls
osa1 Oct 1, 2025
5a1887c
Move QVar and RVar fields to their own types
osa1 Oct 1, 2025
47032df
Create a directory for type checker modules
osa1 Oct 1, 2025
b0b16ed
Add placeholders for unification functions
osa1 Oct 1, 2025
ff5e891
Start implementing unification
osa1 Oct 2, 2025
94d97c5
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 2, 2025
bf8dbb7
Implement deepNormalize, start implementing collectRows
osa1 Oct 2, 2025
2f2a262
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 3, 2025
a2a83e8
Implement collectRows
osa1 Oct 3, 2025
d9c995d
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 3, 2025
8dc3c4f
More unification
osa1 Oct 4, 2025
29ac400
More unification
osa1 Oct 4, 2025
583e021
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 4, 2025
fc21812
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 8, 2025
d5bed32
Port linkExtension
osa1 Oct 10, 2025
1b9f1bd
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 10, 2025
83a9e00
More unification
osa1 Oct 10, 2025
f13a0e7
Fix a TODO
osa1 Oct 10, 2025
2dde843
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 13, 2025
87bd4eb
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 13, 2025
d75ce06
Add missing imports
osa1 Oct 13, 2025
772b5d2
Simplify TyDefIdx
osa1 Oct 13, 2025
4e0d5c1
Add token values to id types
osa1 Oct 15, 2025
28f91d7
Add err loc and msg to unification errs
osa1 Oct 15, 2025
270a1b7
Start implementing one-way unification
osa1 Oct 15, 2025
9f6323b
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 16, 2025
cdbf1b1
Fix type errs
osa1 Oct 16, 2025
71dcb6b
More unification
osa1 Oct 16, 2025
e133e42
More unification
osa1 Oct 16, 2025
589e7b1
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 16, 2025
78b59fb
More types `TyConDetails`, `TraitDetails`, `TraitMethod`, `TypeDetails`
osa1 Oct 18, 2025
63ffd1f
Start implementing convos
osa1 Oct 18, 2025
a90bc98
Add TypeError type, wip stuff
osa1 Oct 18, 2025
be7beec
More convos
osa1 Oct 18, 2025
5469a40
More convos
osa1 Oct 18, 2025
38b87bb
Conversions = done?
osa1 Oct 18, 2025
706c4a6
Implement TraitEnv
osa1 Oct 18, 2025
83fb846
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 18, 2025
a6bc166
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 18, 2025
81af533
Update sytnax in some docs
osa1 Oct 19, 2025
ef28810
WIP
osa1 Oct 19, 2025
8a34396
Merge remote-tracking branch 'origin/main' into type_checking
osa1 Oct 19, 2025
f0088ae
Module and fun envs
osa1 Oct 19, 2025
e033c65
Placeholders
osa1 Oct 19, 2025
2444f20
Fix import
osa1 Oct 19, 2025
e018ede
WIP
osa1 Oct 21, 2025
8f2b0fd
Fix imports again
osa1 Oct 21, 2025
6031c2b
Code
osa1 Oct 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 23 additions & 53 deletions Compiler/Ast.fir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import [
Compiler/Defs,
Compiler/Token,
Compiler/TypeCheck/Ty,
]


Expand Down Expand Up @@ -98,18 +99,6 @@ type ConDecl(
)


#[derive(ToDoc)]
type Kind:
Star
Row(RecordOrVariant)


#[derive(ToDoc)]
type RecordOrVariant:
Record
Variant


#[derive(ToDoc)]
type ConFields:
Empty
Expand Down Expand Up @@ -194,10 +183,10 @@ type TraitDecl(
##
## ```
## impl[ToStr[a]] ToStr[Vec[a]]:
## toStr(self): Str = ...
## toStr(self) Str: ...
##
## impl Iterator[VecIter[a], a]:
## next(self): Option[a] = ...
## next(self) Option[a]: ...
## ```
#[derive(ToDoc)]
type ImplDecl(
Expand Down Expand Up @@ -384,6 +373,12 @@ type NamedType(
)


NamedType.numTyArgs(self) U32:
match self.args:
Option.None: 0
Option.Some(args): args.args.len()


impl Tokens[NamedType]:
firstToken(self: NamedType) TokenIdx:
self.name.token
Expand Down Expand Up @@ -499,14 +494,12 @@ type ForStmt(
astTy: Option[Type],

## `ast_ty`, converted to type checking types by the type checker.
tcTy: Option[Type], # TODO: type-checking type

tcTy: Option[Ty],

expr: Expr,

## Filled in by the type checker: the iterator type. `iter` in `Iterator[iter, item]`.
exprTy: Option[Type], # TODO: type-checking type

exprTy: Option[Ty],

body: Vec[Stmt],

Expand Down Expand Up @@ -651,8 +644,7 @@ type VarPat(
var_: Id,

## Inferred type of the binder. Filled in by the type checker.
ty: Option[Type], # TODO: This should be type-checking type instead of AST type

ty: Option[Ty],
)


Expand Down Expand Up @@ -685,9 +677,7 @@ impl Tokens[ConstrPat]:
type RecordPat(
fields: Vec[Named[Pat]],
ignoreRest: Bool,

# TODO: This should be type-checking type instead of AST type
inferredTy: Option[Type],
inferredTy: Option[Ty],
_firstToken: TokenIdx,
_lastToken: TokenIdx,
)
Expand Down Expand Up @@ -947,8 +937,7 @@ type MethodSelectExpr(
# TODO: We could also add types to every expression if it's going to help with monomorphisation.
# For efficiency though, we should only annotate inferred types and then type check from
# the top-level expression every time we need to compute type of an expr.
# TODO: This should be a type-checking type.
objectTy: Option[Type],
objectTy: Option[Ty],

## The type or trait id that defines the method.
##
Expand All @@ -964,14 +953,13 @@ type MethodSelectExpr(

## Type arguments of `method_ty_id`.
##
## If the method is for a trait, the first arguments here will be for the trait type parameters.
## E.g. in `Iterator.next`, the first two argumetns will be the `iter` and `item` parameters of
## `trait Iterator[iter, item]`.
## If the method is for a trait, the first arguments here will be for the
## trait type parameters. E.g. in `Iterator.next`, the first two argumetns
## will be the `iter` and `item` parameters of `trait Iterator[iter, item]`.
##
## (If the method is not a trait method, then we don't care about the type parameter order.. I
## think?)
tyArgs: Vec[Type], # TODO: type-checking type

## (If the method is not a trait method, then we don't care about the type
## parameter order.. I think?)
tyArgs: Vec[Ty],

_lastToken: TokenIdx,
)
Expand Down Expand Up @@ -1001,9 +989,9 @@ type AssocFnSelectExpr(
## Type arguments explicitly passed to the variable.
userTyArgs: Option[TyArgs],

## Inferred type arguments of the type and associated function. Filled in by the type checker.
tyArgs: Vec[Type], # TODO: type-checking type

## Inferred type arguments of the type and associated function. Filled in by
## the type checker.
tyArgs: Vec[Ty],

_lastToken: TokenIdx,
)
Expand Down Expand Up @@ -1506,24 +1494,6 @@ impl ToDoc[ConDecl]:
Doc.grouped(Doc.str("ConDecl") + Doc.char('(') + args)


impl ToDoc[Kind]:
toDoc(self: Kind) Doc:
match self:
Kind.Star: Doc.str("Kind.Star")
Kind.Row(i0):
let args = Doc.break_(0)
args += i0.toDoc()
args = args.nest(4).group() + Doc.break_(0) + Doc.char(')')
Doc.grouped(Doc.str("Kind.Row") + Doc.char('(') + args)


impl ToDoc[RecordOrVariant]:
toDoc(self: RecordOrVariant) Doc:
match self:
RecordOrVariant.Record: Doc.str("RecordOrVariant.Record")
RecordOrVariant.Variant: Doc.str("RecordOrVariant.Variant")


impl ToDoc[ConFields]:
toDoc(self: ConFields) Doc:
match self:
Expand Down
Loading