Symbol has DefId not Option<DefId>

This commit is contained in:
Greg Shuflin 2021-12-07 02:11:27 -08:00
parent 354dd7d8c1
commit b778428e98
2 changed files with 12 additions and 12 deletions

View File

@ -32,7 +32,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
// First reduce all functions
// TODO once this works, maybe rewrite it using the Visitor
for statement in ast.statements.statements.iter() {
self.top_level_statement(statement);
self.top_level_definition(statement);
}
// Then compute the entrypoint statements (which may reference previously-computed
@ -51,7 +51,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
..
}) => {
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
let def_id = symbol.def_id().unwrap();
let def_id = symbol.def_id();
entrypoint.push(Statement::Binding {
id: def_id,
constant: *constant,
@ -65,7 +65,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
ReducedIR { functions: self.functions, entrypoint }
}
fn top_level_statement(&mut self, statement: &ast::Statement) {
fn top_level_definition(&mut self, statement: &ast::Statement) {
let ast::Statement { id: item_id, kind, .. } = statement;
match kind {
ast::StatementKind::Expression(_expr) => {
@ -96,7 +96,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
}
ast::Declaration::Binding { constant, expr, .. } => {
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
let def_id = symbol.def_id().unwrap();
let def_id = symbol.def_id();
Some(Statement::Binding { id: def_id, constant: *constant, expr: self.expression(expr) })
}
_ => None,
@ -115,7 +115,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
fn insert_function_definition(&mut self, item_id: &ast::ItemId, statements: &ast::Block) {
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
let def_id = symbol.def_id().unwrap();
let def_id = symbol.def_id();
let function_def = FunctionDefinition { body: self.function_internal_block(statements) };
self.functions.insert(def_id, function_def);
}
@ -307,7 +307,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
let lval = match &lhs.kind {
ast::ExpressionKind::Value(qualified_name) => {
if let Some(symbol) = self.symbol_table.lookup_symbol(&qualified_name.id) {
symbol.def_id().unwrap()
symbol.def_id()
} else {
return ReductionError(format!("Couldn't look up name: {:?}", qualified_name));
}
@ -339,9 +339,9 @@ impl<'a, 'b> Reducer<'a, 'b> {
match symbol.spec() {
Builtin(b) => Expression::Callable(Callable::Builtin(b)),
Func { .. } => Expression::Lookup(Lookup::Function(def_id.unwrap())),
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
Func { .. } => Expression::Lookup(Lookup::Function(def_id)),
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id)),
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id)),
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
DataConstructor { tag, type_id } =>
Expression::Callable(Callable::DataConstructor { type_id, tag }),
@ -394,7 +394,7 @@ impl ast::Pattern {
SymbolSpec::DataConstructor { tag, type_id: _ } =>
Pattern::Tuple { tag: Some(tag), subpatterns: vec![] },
SymbolSpec::LocalVariable => {
let def_id = symbol.def_id().unwrap();
let def_id = symbol.def_id();
Pattern::Binding(def_id)
}
spec => return Err(format!("Unexpected VarOrName symbol: {:?}", spec).into()),

View File

@ -188,8 +188,8 @@ impl Symbol {
self.local_name.as_ref()
}
pub fn def_id(&self) -> Option<DefId> {
Some(self.def_id)
pub fn def_id(&self) -> DefId {
self.def_id
}
pub fn spec(&self) -> SymbolSpec {