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

feat: Adds data structures #64

Merged
merged 21 commits into from
Jan 11, 2020
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c84a7bf
feat: parsing of data structures
Wodann Nov 23, 2019
9a86797
feat(hir): resolve struct names
Wodann Nov 23, 2019
e241e86
improvement(struct): allow trailing semicolon
Wodann Nov 29, 2019
0b10bb1
feat(tuple): add parsing and HIR lowering for tuples
baszalmstra Nov 30, 2019
0ecdd6b
feat(structs): generate type ir for structs
baszalmstra Nov 30, 2019
7976f07
feat(struct): parsing of record literals
baszalmstra Dec 1, 2019
76e9188
feat(struct): type inference of record literals
Wodann Dec 4, 2019
b2aea8b
feat(struct): type inference of tuple literals
Wodann Dec 4, 2019
a6303a1
feat(struct): add lexing of indices, and parsing and type inferencing…
Wodann Dec 5, 2019
9c9758e
feat(struct): add IR generation for record, tuple, and unit struct li…
Wodann Dec 12, 2019
5d34607
feat(struct): add struct to ABI and runtime dispatch table
Wodann Dec 16, 2019
1069b9e
feat(struct): add IR generation for fields
Wodann Dec 17, 2019
d6dda23
misc(mun_hir): expression validator
baszalmstra Jan 10, 2020
afe18e1
feat: diagnostics for uninitialized variable access
baszalmstra Jan 10, 2020
d53ee2c
feat: struct memory type specifiers
baszalmstra Jan 10, 2020
a288b1f
feat: visibility can now include specifiers
baszalmstra Jan 10, 2020
0d41201
refactor: Renamed Source to InFile and added to diagnostics
baszalmstra Jan 10, 2020
e5f1fe8
misc: better diagnostic for uninitialized access
baszalmstra Jan 10, 2020
0e75842
feat(struct): add validity checks and diagnostics for struct literals
Wodann Jan 11, 2020
26621df
feat: initial very leaky implementation of heap allocation
baszalmstra Jan 11, 2020
a2c7ce7
misc: suggestions from review
baszalmstra Jan 11, 2020
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
Prev Previous commit
Next Next commit
misc(mun_hir): expression validator
baszalmstra committed Jan 11, 2020
commit d6dda233e1990cf2ed9552d731f67b06eb1cb289
14 changes: 7 additions & 7 deletions crates/mun_hir/src/code_model.rs
Original file line number Diff line number Diff line change
@@ -2,10 +2,13 @@ pub(crate) mod src;

use self::src::HasSource;
use crate::adt::{StructData, StructFieldId};
use crate::code_model::diagnostics::ModuleDefinitionDiagnostic;
use crate::diagnostics::DiagnosticSink;
use crate::expr::validator::ExprValidator;
use crate::expr::{Body, BodySourceMap};
use crate::ids::AstItemDef;
use crate::ids::LocationCtx;
use crate::name::*;
use crate::name_resolution::Namespace;
use crate::raw::{DefKind, RawFileItem};
use crate::resolve::{Resolution, Resolver};
@@ -157,7 +160,7 @@ impl DefWithBody {
}

pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
db.body_hir(self)
db.body(self)
}

pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
@@ -307,7 +310,7 @@ impl Function {
}

pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
db.body_hir(self.into())
db.body(self.into())
}

pub fn ty(self, db: &impl HirDatabase) -> Ty {
@@ -330,8 +333,8 @@ impl Function {
pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
let infer = self.infer(db);
infer.add_diagnostics(db, self, sink);
// let mut validator = ExprValidator::new(self, infer, sink);
// validator.validate_body(db);
let mut validator = ExprValidator::new(self, db, sink);
validator.validate_body();
}
}

@@ -342,9 +345,6 @@ pub enum BuiltinType {
Boolean,
}

use crate::code_model::diagnostics::ModuleDefinitionDiagnostic;
use crate::name::*;

impl BuiltinType {
#[rustfmt::skip]
pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[
2 changes: 1 addition & 1 deletion crates/mun_hir/src/db.rs
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ pub trait HirDatabase: DefDatabase {
fn module_data(&self, file_id: FileId) -> Arc<ModuleData>;

#[salsa::invoke(crate::expr::body_hir_query)]
fn body_hir(&self, def: DefWithBody) -> Arc<crate::expr::Body>;
fn body(&self, def: DefWithBody) -> Arc<crate::expr::Body>;

#[salsa::invoke(crate::expr::body_with_source_map_query)]
fn body_with_source_map(
1 change: 1 addition & 0 deletions crates/mun_hir/src/expr.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ use crate::resolve::Resolver;
use std::mem;

pub(crate) mod scope;
pub(crate) mod validator;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ExprId(RawId);
2 changes: 1 addition & 1 deletion crates/mun_hir/src/expr/scope.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ pub(crate) struct ScopeData {

impl ExprScopes {
pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
let body = db.body_hir(def);
let body = db.body(def);
let res = ExprScopes::new(body);
Arc::new(res)
}
28 changes: 28 additions & 0 deletions crates/mun_hir/src/expr/validator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::{diagnostics::DiagnosticSink, Body, Function, HirDatabase, InferenceResult};
use std::sync::Arc;

mod uninitialized_access;

pub struct ExprValidator<'a, 'b: 'a, 'd, DB: HirDatabase> {
func: Function,
infer: Arc<InferenceResult>,
body: Arc<Body>,
sink: &'a mut DiagnosticSink<'b>,
db: &'d DB,
}

impl<'a, 'b, 'd, DB: HirDatabase> ExprValidator<'a, 'b, 'd, DB> {
pub fn new(func: Function, db: &'d DB, sink: &'a mut DiagnosticSink<'b>) -> Self {
ExprValidator {
func,
sink,
db,
infer: db.infer(func.into()),
body: db.body(func.into()),
}
}

pub fn validate_body(&mut self) {
self.validate_uninitialized_access();
}
}
57 changes: 57 additions & 0 deletions crates/mun_hir/src/expr/validator/uninitialized_access.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use super::ExprValidator;
use crate::HirDatabase;
//use crate::{HirDatabase, ExprId, PatId, Expr, Path};
//use std::collections::HashSet;

//enum ExprSide {
// left,
// Expr
//}

impl<'a, 'b, 'd, D: HirDatabase> ExprValidator<'a, 'b, 'd, D> {
/// Validates that all binding access has previously been initialized.
pub(super) fn validate_uninitialized_access(&mut self) {
// let mut initialized_patterns = HashSet::new();
//
// // Add all parameter patterns to the set of initialized patterns (they must have been
// // initialized)
// for (pat, _) in self.body.params.iter() {
// initialized_patterns.insert(*pat)
// }
//
// self.validate_expr_access(&mut initialized_patterns, self.body.body_expr);
}

// /// Validates that the specified expr does not access unitialized bindings
// fn validate_expr_access(&mut self, initialized_patterns: &mut HashSet<PatId>, expr: ExprId, exprSide:ExprSide) {
// let body = self.body.clone();
// match &body[expr] {
// Expr::Call { callee, args } => {
// self.validate_expr_access(initialized_patterns, *callee);
// for arg in args.iter() {
// self.validate_expr_access(initialized_patterns, *callee);
// }
// },
// Expr::Path(p) => {
// let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr);
// self.validate_path_access(initialized_patterns, &resolver, p);
// }
// Expr::If { .. } => {},
// Expr::UnaryOp { .. } => {},
// Expr::BinaryOp { .. } => {},
// Expr::Block { .. } => {},
// Expr::Return { .. } => {},
// Expr::Break { .. } => {},
// Expr::Loop { .. } => {},
// Expr::While { .. } => {},
// Expr::RecordLit { .. } => {},
// Expr::Field { .. } => {},
// Expr::Literal(_) => {},
// Expr::Missing => {},
// }
// }
//
// fn validate_expr_access(&mut self, initialized_patterns: &mut HashSet<PatId>, p: &Path) {
//
// }
}