Skip to content

Commit af28a27

Browse files
committed
Make it build successfully and add some comments
1 parent 07beba5 commit af28a27

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

crates/formality-check/src/fns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use formality_rust::{
55
};
66
use formality_types::grammar::{Fallible, Wcs};
77

8-
use crate::{mini_rust_check, Check};
8+
use crate::Check;
99

1010
impl Check<'_> {
1111
/// A "free function" is a free-standing function that is not part of an impl.
@@ -59,7 +59,7 @@ impl Check<'_> {
5959
for input_ty in &input_tys {
6060
self.prove_goal(&env, &fn_assumptions, input_ty.well_formed())?;
6161
}
62-
self.prove_goal(&env, &fn_assumptions, output_ty.well_formed())?;
62+
self.prove_goal(&env, &fn_assumptions, &output_ty.well_formed())?;
6363

6464
// Type-check the function body, if present.
6565
match body {
@@ -71,7 +71,7 @@ impl Check<'_> {
7171
// A trusted function body is assumed to be valid, all set.
7272
}
7373
formality_rust::grammar::FnBody::MiniRust(body) => {
74-
mini_rust_check::check_body(&env, &fn_assumptions, body)?;
74+
self.check_body(&env, &output_ty, &fn_assumptions, body)?;
7575
}
7676
}
7777
}

crates/formality-check/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![allow(dead_code)]
22

3-
use formality_types::rust::FormalityLang;
4-
53
use std::{collections::VecDeque, fmt::Debug};
64

75
use anyhow::bail;
@@ -13,7 +11,7 @@ use formality_rust::{
1311
};
1412
use formality_types::grammar::{Fallible, Wcs};
1513

16-
mod mini_rust_check;;
14+
mod mini_rust_check;
1715

1816
/// Check all crates in the program. The crates must be in dependency order
1917
/// such that any prefix of the crates is a complete program.

crates/formality-check/src/mini_rust_check.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use formality_core::{term, Fallible, Map, Upcast};
1+
use formality_core::{Fallible, Map, Upcast};
22
use formality_prove::Env;
33
use formality_rust::grammar::minirust::{self, LocalId};
44
use formality_types::grammar::{Ty, Wcs, Relation};
@@ -39,7 +39,7 @@ impl Check<'_> {
3939
)?;
4040

4141
let env = TypeckEnv {
42-
env,
42+
env: env.clone(),
4343
output_ty,
4444
local_variables,
4545
};
@@ -57,43 +57,47 @@ impl Check<'_> {
5757
self.check_statement(env, statement)?;
5858
}
5959

60-
self.check_terminator(&block.terminator)?;
60+
self.check_terminator(env, &block.terminator)?;
6161

6262
Ok(())
6363
}
6464

65-
fn check_statement(&self, env: &TypeckEnv, statement: &minirust::Statement) -> Fallible<()> {
65+
fn check_statement(&self, _env: &TypeckEnv, statement: &minirust::Statement) -> Fallible<()> {
6666
match statement {
67-
minirust::Statement::Assign(place_expression, value_expression) => {
67+
minirust::Statement::Assign(_place_expression, _value_expression) => {
6868
// FIXME: check that the place and value are well-formed
6969
// FIXME: check that the type of the value is a subtype of the place's type
70+
todo!();
7071
}
71-
minirust::Statement::PlaceMention(place_expression) => {
72+
minirust::Statement::PlaceMention(_place_expression) => {
7273
// FIXME: check that the place is well-formed
7374
// FIXME: check that access the place is allowed per borrowck rules
75+
todo!();
7476
}
7577
}
7678
}
7779

78-
fn check_terminator(&self, env: &TypeckEnv, terminator: &minirust::Terminator) -> Fallible<()> {
80+
fn check_terminator(&self, _env: &TypeckEnv, terminator: &minirust::Terminator) -> Fallible<()> {
7981
match terminator {
80-
minirust::Terminator::Goto(bb_id) => {
82+
minirust::Terminator::Goto(_bb_id) => {
8183
// FIXME: Check that the basic block `bb_id` exists
84+
todo!();
8285
}
83-
minirust::Terminator::Call { callee, arguments, ret, next_block } => {
86+
minirust::Terminator::Call { callee:_, generic_arguments:_, arguments:_, ret:_, next_block:_ } => {
8487
// FIXME: check that the callee is something callable
8588
// FIXME: check that the arguments are well formed and their types are subtypes of the expected argument types
8689
// FIXME: check that the next block is valid
8790
// FIXME: check that the fn's declared return type is a subtype of the type of the local variable `ret`
91+
todo!();
8892
}
8993
minirust::Terminator::Return => {
9094
// FIXME: Check that the return local variable has been initialized
95+
todo!();
9196
}
9297
}
9398
}
9499
}
95100

96-
#[term]
97101
struct TypeckEnv {
98102
env: Env,
99103

crates/formality-rust/src/grammar/minirust.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub enum Statement {
6363
#[grammar($v0 = $v1;)]
6464
Assign(PlaceExpression, ValueExpression),
6565

66+
// Represent let _ = place;
6667
#[grammar($v0;)]
6768
PlaceMention(PlaceExpression),
6869

@@ -89,14 +90,19 @@ pub enum Terminator {
8990
// call foo.add<u32>(x, y)
9091
#[grammar(call $callee $<?generic_arguments> $(arguments) -> $ret $:goto $next_block)]
9192
Call {
93+
/// What function or method to call.
9294
callee: ValueExpression,
9395
// cc: CallingConvention,
9496
generic_arguments: Vec<Parameter>,
97+
/// The function arguments to pass.
9598
arguments: Vec<ArgumentExpression>,
99+
/// The place to put the return value into.
96100
ret: PlaceExpression,
101+
/// The block to jump to when this call returns.
97102
next_block: Option<BbId>,
98103
},
99104

105+
/// Return from the current function.
100106
#[grammar(return)]
101107
Return,
102108
}

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(control_flow_enum)]
2-
31
use std::{path::PathBuf, sync::Arc};
42

53
use clap::Parser;

0 commit comments

Comments
 (0)