Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten typesets #677

Merged
merged 30 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a3ea472
xparser: Parse literals as types
CohenArthur Apr 24, 2024
70c45dc
name_resolve: Handle type literals properly by doing nothing
CohenArthur Apr 24, 2024
68c63c5
dedup: Add constant deduplication
CohenArthur Apr 28, 2024
d170e00
fir: Allow constants to refer to themselves as types
CohenArthur Apr 27, 2024
ed0da6a
error: Add From<Vec<Into<Error>>> to allow Fallible<Infallible> in Tr…
CohenArthur Apr 28, 2024
1a51196
fir: Add IndexMut impl, cleanup Index impl
CohenArthur Apr 28, 2024
7299231
tyck: Add typechecking of literal types
CohenArthur Apr 28, 2024
ec182cc
tyck: Build bool as a union type of constants too
CohenArthur Apr 28, 2024
63c65dd
[wip] widen: Add base for widening typesets
CohenArthur Apr 29, 2024
11b7821
[wip]: more wip
CohenArthur Jun 2, 2024
21937e3
[wip] widen: Done?
CohenArthur Jun 6, 2024
59e8dae
tyck: Clean up implementation of `widen`
CohenArthur Aug 29, 2024
4b2534a
checker: Do not default to unit type when node is not present in typectx
CohenArthur Aug 29, 2024
f3185b3
widen: Keep track of nodes when creating new TypeMap
CohenArthur Aug 29, 2024
847135f
tyck: Build float as a union of all float constants too
CohenArthur Sep 2, 2024
f6b3e8e
tyck: Workaround test failure in type error formatting code
CohenArthur Sep 3, 2024
284c31e
builtins: Create builtin types as a union type
CohenArthur Sep 3, 2024
3f06dc5
debug-fir: Clean-up implementation slightly
CohenArthur Sep 13, 2024
6b2cd3f
interpreter: Show constant values in Fir formatter
CohenArthur Sep 13, 2024
ae5589d
tyck: Fix widening of binary operations
CohenArthur Sep 13, 2024
36d1a52
tyck: Split arithmetic builtins into Comparable and Equalable types
CohenArthur Sep 13, 2024
3edfcce
chore: Clippy fix old code
CohenArthur Sep 13, 2024
e9004f3
tyck: Add testcases mentioned in #677
CohenArthur Sep 13, 2024
e3ddd4b
chore: Clippy fixes
CohenArthur Sep 14, 2024
3804872
builtins: Cleanup operators and add Equality kind
CohenArthur Sep 14, 2024
3df5ac2
dedup: Add deduplication of float literals
CohenArthur Sep 25, 2024
f24a6c4
tools: Add deduplication benchmark tool
CohenArthur Sep 25, 2024
ec533da
chore: Formatting
CohenArthur Sep 25, 2024
06f0901
chore: Remove deadcode
CohenArthur Sep 25, 2024
0f58ad2
dedup_bench: Remove output
CohenArthur Sep 25, 2024
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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"ast",
"fir",
"flatten",
"dedup",
"name_resolve",
"include_code",
"loop_desugar",
Expand All @@ -35,6 +36,7 @@ ast = { path = "ast" }
ast-sanitizer = { path = "ast-sanitizer" }
fir = { path = "fir" }
debug-fir = { path = "debug-fir" }
dedup = { path = "dedup" }
flatten = { path = "flatten" }
name_resolve = { path = "name_resolve" }
symbol = { path = "symbol" }
Expand Down
15 changes: 15 additions & 0 deletions ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Abstract Syntax Tree representation of jinko's source code

use std::fmt;

use error::{ErrKind, Error};
use location::SpanTuple;
use symbol::Symbol;
Expand All @@ -10,6 +12,7 @@ pub enum TypeKind {
// probably simpler, right?
// but then how do we handle a simple type like "int" without generics or anything -> symbol(int) and empty vec for generics so we're good
Simple(Symbol), // FIXME: Can this be a symbol? Should it be something else? I think Symbol is fine, because the struct enclosing TypeKind has generics and location
Literal(Box<Ast>),
Multi(Vec<Type>),
FunctionLike(Vec<Type>, Option<Box<Type>>),
}
Expand Down Expand Up @@ -136,6 +139,18 @@ pub enum Value {
Str(String),
}

impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Value::Integer(v) => write!(f, "{v}"),
Value::Float(v) => write!(f, "{v}"),
Value::Bool(v) => write!(f, "{v}"),
Value::Char(v) => write!(f, "'{v}'"),
Value::Str(v) => write!(f, "\"{v}\""),
}
}
}

// FIXME: How to keep location in there? How to do it ergonomically?
// As a "Smart pointer" type? E.g by having it implement `Deref<T = AstInner>`?
// Would that even work? If it does, it is ergonomic but boy is it not idiomatic
Expand Down
22 changes: 19 additions & 3 deletions builtins/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,37 @@ pub fn argument(name: &str, ty: Type) -> TypedValue {
}
}

pub fn ty_arg(ty: BuiltinType) -> Type {
pub fn type_symbol(symbol: &str) -> Type {
Type {
kind: TypeKind::Simple(Symbol::from(symbol)),
location: SpanTuple::builtin(),
generics: vec![],
}
}

pub fn builtin_type_symbol(ty: BuiltinType) -> Type {
Type {
kind: TypeKind::Simple(Symbol::from(ty.name())),
location: SpanTuple::builtin(),
generics: vec![],
}
}

pub fn ty(ty: BuiltinType) -> Ast {
fn union_content(types: Vec<Type>) -> TypeContent {
TypeContent::Alias(Type {
kind: TypeKind::Multi(types),
location: SpanTuple::builtin(),
generics: vec![],
})
}

pub fn union_type(ty: BuiltinType, variants: Vec<Type>) -> Ast {
Ast {
location: SpanTuple::builtin(),
node: Node::Type {
name: Symbol::from(ty.name()),
fields: union_content(variants),
generics: vec![],
fields: TypeContent::None,
with: None,
},
}
Expand Down
Loading
Loading