Skip to content

Commit

Permalink
perf(compiler): Shrink the core::Expr type to 40 bytes (from 72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Apr 29, 2019
1 parent cd2dd36 commit 779d1b6
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 61 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 8 additions & 7 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ documentation = "https://docs.rs/gluon"
build = "build.rs"

[dependencies]
bitflags = "1.0.0"
codespan = "0.2"
collect-mac = "0.1.0"
frunk_core = "0.2"
futures = "0.1.0"
itertools = "0.8"
log = "0.4"
quick-error = "1.1.0"
mopa = "0.2.2"
collect-mac = "0.1.0"
ordered-float = "1"
pretty = "0.5"
bitflags = "1.0.0"
itertools = "0.8"
futures = "0.1.0"
typed-arena = "1.2.0"
quick-error = "1.1.0"
smallvec = "0.6"
codespan = "0.2"
typed-arena = "1.2.0"

serde = { version = "1.0.0", optional = true }
serde_json = { version = "1.0.0", optional = true }
Expand Down
14 changes: 7 additions & 7 deletions vm/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::{Deref, DerefMut};

use crate::base::{
ast::{self, DisplayEnv, Literal, Typed, TypedIdent},
ast::{DisplayEnv, Typed, TypedIdent},
kind::{ArcKind, KindEnv},
pos::Line,
resolve,
Expand All @@ -12,7 +12,7 @@ use crate::base::{
};

use crate::{
core::{self, CExpr, Expr, Pattern},
core::{self, CExpr, Expr, Literal, Pattern},
interner::InternedStr,
source_map::{LocalMap, SourceMap},
types::*,
Expand Down Expand Up @@ -815,27 +815,27 @@ impl<'a> Compiler<'a> {
Pattern::Literal(ref l) => {
let lhs_i = function.stack_size() - 1;
match *l {
ast::Literal::Byte(b) => {
Literal::Byte(b) => {
function.emit(Push(lhs_i));
function.emit(PushByte(b));
function.emit(ByteEQ);
}
ast::Literal::Int(i) => {
Literal::Int(i) => {
function.emit(Push(lhs_i));
function.emit(PushInt(i));
function.emit(IntEQ);
}
ast::Literal::Char(ch) => {
Literal::Char(ch) => {
function.emit(Push(lhs_i));
function.emit(PushInt(u32::from(ch).into()));
function.emit(IntEQ);
}
ast::Literal::Float(f) => {
Literal::Float(f) => {
function.emit(Push(lhs_i));
function.emit(PushFloat(f.into_inner()));
function.emit(FloatEQ);
}
ast::Literal::String(ref s) => {
Literal::String(ref s) => {
self.load_identifier(&Symbol::from("@string_eq"), function)?;
let lhs_i = function.stack_size() - 2;
function.emit(Push(lhs_i));
Expand Down
8 changes: 4 additions & 4 deletions vm/src/core/grammar.lalrpop
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::base::{
ast::{Literal, TypedIdent},
ast::{TypedIdent},
pos::{BytePos, Span},
symbol::{Symbol, Symbols},
types::{Field, Type}};

use crate::core::{Allocator, Alternative, Closure, Expr, LetBinding, Named, Pattern};
use crate::core::{Allocator, Alternative, Closure, Expr, LetBinding, Literal, Named, Pattern};

grammar<'env, 'a>(symbols: &'env mut Symbols, allocator: &'a Allocator<'a>);

Expand All @@ -27,7 +27,7 @@ Field: (Symbol, Option<Symbol>) = {

Literal: Literal = {
<r"[0-9]+"> => Literal::Int(<>.parse().unwrap()),
<r#""[^"]*""#> => Literal::String(<>[1..<>.len() - 1].to_string()),
<r#""[^"]*""#> => Literal::String(Box::from(&<>[1..<>.len() - 1])),
};

Pattern: Pattern = {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub Expr: Expr<'a> = {
}
},
<bind: LetBinding> "in" <expr: AllocExpr> => {
Expr::Let(bind, expr)
Expr::Let(allocator.let_binding_arena.alloc(bind), expr)
},
"match" <expr: AllocExpr> "with" <alts: Alternative+> "end" =>
Expr::Match(expr, allocator.alternative_arena.alloc_extend(alts.into_iter())),
Expand Down
8 changes: 4 additions & 4 deletions vm/src/core/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::{Deref, DerefMut};

use crate::base::{
ast::{Literal, TypedIdent},
ast::TypedIdent,
fnv::FnvSet,
kind::{ArcKind, KindEnv},
merge::merge_iter,
Expand All @@ -14,7 +14,7 @@ use crate::{
core::{
self,
optimize::{walk_expr_alloc, DifferentLifetime, ExprProducer, SameLifetime, Visitor},
Allocator, CExpr, Closure, Expr, LetBinding, Named, Pattern,
Allocator, CExpr, Closure, Expr, LetBinding, Literal, Named, Pattern,
},
types::*,
Error, Result,
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<'a, 'e> Compiler<'a, 'e> {
};
if variable_in_value {
value = Some(Reduced::Local(&*self.allocator.arena.alloc(Expr::Let(
bind,
self.allocator.let_binding_arena.alloc(bind),
value.map_or(expr, |value| value.into_local(allocator)),
))));
}
Expand Down Expand Up @@ -524,7 +524,7 @@ impl<'a, 'e> Compiler<'a, 'e> {
if let Some(expr) = new_named {
self.bindings.push(LetBinding {
expr,
..let_binding.clone()
..(*let_binding).clone()
});
}
return Ok(TailCall::Tail(body));
Expand Down
Loading

0 comments on commit 779d1b6

Please sign in to comment.