Decouple type checking info from CST and refactor checker.ts a bit

This commit is contained in:
Sam Vervaeck 2023-08-12 13:46:19 +02:00
parent aa386f2e79
commit e92e346bad
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
4 changed files with 365 additions and 284 deletions

View file

@ -23,6 +23,22 @@ nice goodies, including:
- **Cross-platform standard library**, allowing you to write your code for the
web and the desktop at the same time.
## Examples
_Note that these examples are stil in the design phase and not able to compile._
```ocaml
import "html" ( HtmlComponent )
let app : HtmlComponent.
let { fullname, .. } = perform get_app_state
return match user.
None => h1 [ "Please log in." ]
Some({ fullname, .. }) =>
```
## Core Principles
Bolt has a few fundamental design principles that we hope in time will make it

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ import path from "path"
import { assert, implementationLimitation, IndentWriter, JSONObject, JSONValue, nonenumerable, unreachable } from "./util";
import { isNodeWithScope, Scope } from "./scope"
import type { InferContext, Kind, KindEnv, Scheme, TypeEnv } from "./checker"
import type { Kind, Scheme } from "./checker"
import type { Type } from "./types";
import { Emitter } from "./emitter";
@ -253,11 +253,6 @@ abstract class SyntaxBase {
@nonenumerable
public parent: Syntax | null = null;
@nonenumerable
public inferredKind?: Kind;
@nonenumerable
public inferredType?: Type;
public abstract getFirstToken(): Token;
public abstract getLastToken(): Token;
@ -296,6 +291,10 @@ abstract class SyntaxBase {
throw new Error(`Could not find a scope for ${this}. Maybe the parent links are not set?`);
}
public getParentScope(): Scope | null {
return this.parent === null ? null : this.parent.getScope();
}
public getEnclosingModule(): ModuleDeclaration | SourceFile {
let curr = this.parent!;
while (curr !== null) {
@ -2595,9 +2594,6 @@ export class EnumDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.EnumDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public enumKeyword: EnumKeyword,
@ -2668,9 +2664,6 @@ export class StructDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.StructDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public structKeyword: StructKeyword,
@ -2836,9 +2829,6 @@ export class TypeDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.TypeDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public typeKeyword: TypeKeyword,
@ -2881,17 +2871,11 @@ export class LetDeclaration extends SyntaxBase {
@nonenumerable
public scope?: Scope;
@nonenumerable
public typeEnv?: TypeEnv;
@nonenumerable
public activeCycle?: boolean;
@nonenumerable
public visited?: boolean;
@nonenumerable
public context?: InferContext;
public constructor(
public pubKeyword: PubKeyword | null,
public letKeyword: LetKeyword,
@ -3082,9 +3066,6 @@ export class ClassDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.ClassDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public classKeyword: ClassKeyword,
@ -3186,9 +3167,6 @@ export class InstanceDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.InstanceDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public classKeyword: InstanceKeyword,
@ -3233,11 +3211,6 @@ export class ModuleDeclaration extends SyntaxBase {
public readonly kind = SyntaxKind.ModuleDeclaration;
@nonenumerable
public typeEnv?: TypeEnv;
@nonenumerable
public kindEnv?: KindEnv;
public constructor(
public pubKeyword: PubKeyword | null,
public modKeyword: ModKeyword,
@ -3287,10 +3260,6 @@ export class SourceFile extends SyntaxBase {
@nonenumerable
public scope?: Scope;
@nonenumerable
public typeEnv?: TypeEnv;
@nonenumerable
public kindEnv?: KindEnv;
public constructor(
private file: TextFile,

View file

@ -50,7 +50,7 @@ export abstract class TypeBase {
this.find().parent = newType;
}
public hasTypeVar(tv: TUniVar): boolean {
public hasTypeVar(tv: TRegularVar): boolean {
for (const other of this.getTypeVars()) {
if (tv.id === other.id) {
return true;
@ -105,7 +105,7 @@ export class TRigidVar extends TypeBase {
}
export class TUniVar extends TypeBase {
export class TRegularVar extends TypeBase {
public readonly kind = TypeKind.UniVar;
@ -122,8 +122,8 @@ export class TUniVar extends TypeBase {
yield this;
}
public shallowClone(): TUniVar {
return new TUniVar(this.id, this.node);
public shallowClone(): TRegularVar {
return new TRegularVar(this.id, this.node);
}
public substitute(sub: TVSub): Type {
@ -451,7 +451,7 @@ export type Type
= TCon
| TArrow
| TRigidVar
| TUniVar
| TRegularVar
| TApp
| TField
| TNil
@ -459,10 +459,9 @@ export type Type
| TAbsent
export type TVar
= TUniVar
= TRegularVar
| TRigidVar
export function typesEqual(a: Type, b: Type): boolean {
if (a.kind !== b.kind) {
return false;