1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

refactor imports

This commit is contained in:
dark64 2021-05-17 13:24:02 +02:00
parent 2ed9e6a972
commit 4dc5bb1121
5 changed files with 290 additions and 478 deletions

View file

@ -6,63 +6,65 @@ use zokrates_pest_ast as pest;
impl<'ast> From<pest::File<'ast>> for absy::Module<'ast> { impl<'ast> From<pest::File<'ast>> for absy::Module<'ast> {
fn from(file: pest::File<'ast>) -> absy::Module<'ast> { fn from(file: pest::File<'ast>) -> absy::Module<'ast> {
absy::Module::with_symbols(file.declarations.into_iter().map(|d| match d { absy::Module::with_symbols(file.declarations.into_iter().flat_map(|d| match d {
pest::SymbolDeclaration::Import(i) => i.into(), pest::SymbolDeclaration::Import(i) => import_directive_to_symbol_vec(i),
pest::SymbolDeclaration::Constant(c) => c.into(), pest::SymbolDeclaration::Constant(c) => vec![c.into()],
pest::SymbolDeclaration::Struct(s) => s.into(), pest::SymbolDeclaration::Struct(s) => vec![s.into()],
pest::SymbolDeclaration::Function(f) => f.into(), pest::SymbolDeclaration::Function(f) => vec![f.into()],
})) }))
} }
} }
impl<'ast> From<pest::ImportDirective<'ast>> for absy::SymbolDeclarationNode<'ast> { fn import_directive_to_symbol_vec(
fn from(import: pest::ImportDirective<'ast>) -> absy::SymbolDeclarationNode<'ast> { import: pest::ImportDirective,
use crate::absy::NodeValue; ) -> Vec<absy::SymbolDeclarationNode> {
use crate::absy::NodeValue;
match import { match import {
pest::ImportDirective::Main(import) => { pest::ImportDirective::Main(import) => {
let span = import.span; let span = import.span;
let source = Path::new(import.source.span.as_str()); let source = Path::new(import.source.span.as_str());
let id = "main";
let import = absy::MainImport { let import = absy::CanonicalImport {
source, source,
alias: import.alias.map(|a| a.span.as_str()), id: absy::SymbolIdentifier::from(id).alias(import.alias.map(|a| a.span.as_str())),
}
.span(span.clone());
absy::SymbolDeclaration {
id: None,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Import(
absy::ImportDirective::Main(import),
)),
}
.span(span)
} }
pest::ImportDirective::From(import) => { .span(span.clone());
let span = import.span;
let source = Path::new(import.source.span.as_str());
let import = absy::FromImport { vec![absy::SymbolDeclaration {
source, id,
symbols: import symbol: absy::Symbol::Here(absy::SymbolDefinition::Import(import)),
.symbols
.into_iter()
.map(|symbol| absy::SymbolIdentifier {
id: symbol.id.span.as_str(),
alias: symbol.alias.map(|a| a.span.as_str()),
})
.collect(),
}
.span(span.clone());
absy::SymbolDeclaration {
id: None,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Import(
absy::ImportDirective::From(import),
)),
}
.span(span)
} }
.span(span.clone())]
}
pest::ImportDirective::From(import) => {
let span = import.span;
let source = Path::new(import.source.span.as_str());
import
.symbols
.into_iter()
.map(|symbol| {
let alias = symbol
.alias
.as_ref()
.map(|a| a.span.as_str())
.unwrap_or_else(|| symbol.id.span.as_str());
let import = absy::CanonicalImport {
source,
id: absy::SymbolIdentifier::from(symbol.id.span.as_str())
.alias(Some(alias)),
}
.span(span.clone());
absy::SymbolDeclaration {
id: alias,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Import(import)),
}
.span(span.clone())
})
.collect()
} }
} }
} }
@ -85,7 +87,7 @@ impl<'ast> From<pest::StructDefinition<'ast>> for absy::SymbolDeclarationNode<'a
.span(span.clone()); .span(span.clone());
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some(id), id,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Struct(ty)), symbol: absy::Symbol::Here(absy::SymbolDefinition::Struct(ty)),
} }
.span(span) .span(span)
@ -120,7 +122,7 @@ impl<'ast> From<pest::ConstantDefinition<'ast>> for absy::SymbolDeclarationNode<
.span(span.clone()); .span(span.clone());
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some(id), id,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Constant(ty)), symbol: absy::Symbol::Here(absy::SymbolDefinition::Constant(ty)),
} }
.span(span) .span(span)
@ -176,7 +178,7 @@ impl<'ast> From<pest::FunctionDefinition<'ast>> for absy::SymbolDeclarationNode<
.span(span.clone()); .span(span.clone());
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some(id), id,
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(function)), symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(function)),
} }
.span(span) .span(span)
@ -782,7 +784,7 @@ mod tests {
let ast = pest::generate_ast(&source).unwrap(); let ast = pest::generate_ast(&source).unwrap();
let expected: absy::Module = absy::Module { let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration { symbols: vec![absy::SymbolDeclaration {
id: Some(&source[4..8]), id: &source[4..8],
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function( symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
absy::Function { absy::Function {
arguments: vec![], arguments: vec![],
@ -813,7 +815,7 @@ mod tests {
let ast = pest::generate_ast(&source).unwrap(); let ast = pest::generate_ast(&source).unwrap();
let expected: absy::Module = absy::Module { let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration { symbols: vec![absy::SymbolDeclaration {
id: Some(&source[4..8]), id: &source[4..8],
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function( symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
absy::Function { absy::Function {
arguments: vec![], arguments: vec![],
@ -843,7 +845,7 @@ mod tests {
let expected: absy::Module = absy::Module { let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration { symbols: vec![absy::SymbolDeclaration {
id: Some(&source[4..8]), id: &source[4..8],
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function( symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
absy::Function { absy::Function {
arguments: vec![ arguments: vec![
@ -896,7 +898,7 @@ mod tests {
fn wrap(ty: UnresolvedType<'static>) -> absy::Module<'static> { fn wrap(ty: UnresolvedType<'static>) -> absy::Module<'static> {
absy::Module { absy::Module {
symbols: vec![absy::SymbolDeclaration { symbols: vec![absy::SymbolDeclaration {
id: Some("main"), id: "main",
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function( symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
absy::Function { absy::Function {
arguments: vec![absy::Parameter::private( arguments: vec![absy::Parameter::private(
@ -969,7 +971,7 @@ mod tests {
fn wrap(expression: absy::Expression<'static>) -> absy::Module { fn wrap(expression: absy::Expression<'static>) -> absy::Module {
absy::Module { absy::Module {
symbols: vec![absy::SymbolDeclaration { symbols: vec![absy::SymbolDeclaration {
id: Some("main"), id: "main",
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function( symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
absy::Function { absy::Function {
arguments: vec![], arguments: vec![],

View file

@ -76,57 +76,16 @@ impl<'ast> fmt::Display for SymbolIdentifier<'ast> {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct MainImport<'ast> { pub struct CanonicalImport<'ast> {
pub source: &'ast Path, pub source: &'ast Path,
pub alias: Option<Identifier<'ast>>, pub id: SymbolIdentifier<'ast>,
} }
pub type MainImportNode<'ast> = Node<MainImport<'ast>>; pub type CanonicalImportNode<'ast> = Node<CanonicalImport<'ast>>;
impl<'ast> fmt::Display for MainImport<'ast> { impl<'ast> fmt::Display for CanonicalImport<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.alias { write!(f, "from \"{}\" import {}", self.source.display(), self.id)
Some(ref alias) => write!(f, "import \"{}\" as {}", self.source.display(), alias),
None => write!(f, "import \"{}\"", self.source.display()),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct FromImport<'ast> {
pub source: &'ast Path,
pub symbols: Vec<SymbolIdentifier<'ast>>,
}
pub type FromImportNode<'ast> = Node<FromImport<'ast>>;
impl<'ast> fmt::Display for FromImport<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"from \"{}\" import {}",
self.source.display(),
self.symbols
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ")
)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImportDirective<'ast> {
Main(MainImportNode<'ast>),
From(FromImportNode<'ast>),
}
impl<'ast> fmt::Display for ImportDirective<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ImportDirective::Main(main) => write!(f, "{}", main),
ImportDirective::From(from) => write!(f, "{}", from),
}
} }
} }
@ -164,14 +123,14 @@ impl<'ast> fmt::Display for SymbolImport<'ast> {
/// A declaration of a symbol /// A declaration of a symbol
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct SymbolDeclaration<'ast> { pub struct SymbolDeclaration<'ast> {
pub id: Option<Identifier<'ast>>, pub id: Identifier<'ast>,
pub symbol: Symbol<'ast>, pub symbol: Symbol<'ast>,
} }
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum SymbolDefinition<'ast> { pub enum SymbolDefinition<'ast> {
Import(ImportDirective<'ast>), Import(CanonicalImportNode<'ast>),
Struct(StructDefinitionNode<'ast>), Struct(StructDefinitionNode<'ast>),
Constant(ConstantDefinitionNode<'ast>), Constant(ConstantDefinitionNode<'ast>),
Function(FunctionNode<'ast>), Function(FunctionNode<'ast>),
@ -189,26 +148,19 @@ impl<'ast> fmt::Display for SymbolDeclaration<'ast> {
match &self.symbol { match &self.symbol {
Symbol::Here(ref symbol) => match symbol { Symbol::Here(ref symbol) => match symbol {
SymbolDefinition::Import(ref i) => write!(f, "{}", i), SymbolDefinition::Import(ref i) => write!(f, "{}", i),
SymbolDefinition::Struct(ref t) => write!(f, "struct {} {}", self.id.unwrap(), t), SymbolDefinition::Struct(ref t) => write!(f, "struct {} {}", self.id, t),
SymbolDefinition::Constant(ref c) => write!( SymbolDefinition::Constant(ref c) => write!(
f, f,
"const {} {} = {}", "const {} {} = {}",
c.value.ty, c.value.ty, self.id, c.value.expression
self.id.unwrap(),
c.value.expression
), ),
SymbolDefinition::Function(ref func) => { SymbolDefinition::Function(ref func) => {
write!(f, "def {}{}", self.id.unwrap(), func) write!(f, "def {}{}", self.id, func)
} }
}, },
Symbol::There(ref i) => write!(f, "{}", i), Symbol::There(ref i) => write!(f, "{}", i),
Symbol::Flat(ref flat_fun) => { Symbol::Flat(ref flat_fun) => {
write!( write!(f, "def {}{}:\n\t// hidden", self.id, flat_fun.signature())
f,
"def {}{}:\n\t// hidden",
self.id.unwrap(),
flat_fun.signature()
)
} }
} }
} }
@ -284,40 +236,6 @@ impl<'ast> fmt::Display for ConstantDefinition<'ast> {
} }
} }
// /// An import
// #[derive(Debug, Clone, PartialEq)]
// pub struct SymbolImport<'ast> {
// /// the id of the symbol in the target module. Note: there may be many candidates as imports statements do not specify the signature. In that case they must all be functions however.
// pub symbol_id: Identifier<'ast>,
// /// the id of the module to import from
// pub module_id: OwnedModuleId,
// }
//
// type SymbolImportNode<'ast> = Node<SymbolImport<'ast>>;
//
// impl<'ast> SymbolImport<'ast> {
// pub fn with_id_in_module<S: Into<Identifier<'ast>>, U: Into<OwnedModuleId>>(
// symbol_id: S,
// module_id: U,
// ) -> Self {
// SymbolImport {
// symbol_id: symbol_id.into(),
// module_id: module_id.into(),
// }
// }
// }
//
// impl<'ast> fmt::Display for SymbolImport<'ast> {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(
// f,
// "from {} import {}",
// self.module_id.display().to_string(),
// self.symbol_id,
// )
// }
// }
impl<'ast> fmt::Display for Module<'ast> { impl<'ast> fmt::Display for Module<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let res = self let res = self

View file

@ -86,8 +86,7 @@ impl<'ast> NodeValue for StructDefinitionField<'ast> {}
impl<'ast> NodeValue for ConstantDefinition<'ast> {} impl<'ast> NodeValue for ConstantDefinition<'ast> {}
impl<'ast> NodeValue for Function<'ast> {} impl<'ast> NodeValue for Function<'ast> {}
impl<'ast> NodeValue for Module<'ast> {} impl<'ast> NodeValue for Module<'ast> {}
impl<'ast> NodeValue for MainImport<'ast> {} impl<'ast> NodeValue for CanonicalImport<'ast> {}
impl<'ast> NodeValue for FromImport<'ast> {}
impl<'ast> NodeValue for SymbolImport<'ast> {} impl<'ast> NodeValue for SymbolImport<'ast> {}
impl<'ast> NodeValue for Variable<'ast> {} impl<'ast> NodeValue for Variable<'ast> {}
impl<'ast> NodeValue for Parameter<'ast> {} impl<'ast> NodeValue for Parameter<'ast> {}

View file

@ -12,7 +12,7 @@ use crate::parser::Position;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::io; use std::io;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use typed_arena::Arena; use typed_arena::Arena;
use zokrates_common::Resolver; use zokrates_common::Resolver;
@ -70,259 +70,153 @@ impl Importer {
for symbol in destination.symbols { for symbol in destination.symbols {
match symbol.value.symbol { match symbol.value.symbol {
Symbol::Here(ref s) => match s { Symbol::Here(SymbolDefinition::Import(import)) => symbols.push(
SymbolDefinition::Import(ImportDirective::Main(main)) => { Importer::resolve::<T, E>(import, &location, resolver, modules, arena)?,
let pos = main.pos(); ),
let module_id = &main.value.source; _ => symbols.push(symbol),
match resolver {
Some(res) => {
match res.resolve(location.clone(), module_id.to_path_buf()) {
Ok((source, new_location)) => {
// generate an alias from the imported path if none was given explicitly
let alias = main.value.alias.or(
module_id
.file_stem()
.ok_or_else(|| {
CompileErrors::from(
CompileErrorInner::ImportError(Error::new(
format!(
"Could not determine alias for import {}",
module_id.display()
),
))
.in_file(&location),
)
})?
.to_str()
);
match modules.get(&new_location) {
Some(_) => {}
None => {
let source = arena.alloc(source);
let compiled = compile_module::<T, E>(
source,
new_location.clone(),
resolver,
modules,
&arena,
)?;
assert!(modules
.insert(new_location.clone(), compiled)
.is_none());
}
};
symbols.push(
SymbolDeclaration {
id: alias,
symbol: Symbol::There(
SymbolImport::with_id_in_module(
"main",
new_location,
)
.start_end(pos.0, pos.1),
),
}
.start_end(pos.0, pos.1),
);
}
Err(err) => {
return Err(CompileErrorInner::ImportError(
err.into().with_pos(Some(pos)),
)
.in_file(&location)
.into());
}
}
}
None => {
return Err(CompileErrorInner::from(Error::new(
"Cannot resolve import without a resolver",
))
.in_file(&location)
.into());
}
}
}
SymbolDefinition::Import(ImportDirective::From(from)) => {
let pos = from.pos();
let module_id = &from.value.source;
match module_id.to_str().unwrap() {
"EMBED" => {
for symbol in &from.value.symbols {
match symbol.id {
#[cfg(feature = "bellman")]
"sha256round" => {
if T::id() != Bn128Field::id() {
return Err(CompileErrorInner::ImportError(
Error::new(format!(
"Embed sha256round cannot be used with curve {}",
T::name()
))
.with_pos(Some(pos)),
).in_file(&location).into());
} else {
symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(
FlatEmbed::Sha256Round,
),
}
.start_end(pos.0, pos.1),
)
}
}
"unpack" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::Unpack),
}
.start_end(pos.0, pos.1),
),
"u64_to_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U64ToBits),
}
.start_end(pos.0, pos.1),
),
"u32_to_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U32ToBits),
}
.start_end(pos.0, pos.1),
),
"u16_to_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U16ToBits),
}
.start_end(pos.0, pos.1),
),
"u8_to_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U8ToBits),
}
.start_end(pos.0, pos.1),
),
"u64_from_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U64FromBits),
}
.start_end(pos.0, pos.1),
),
"u32_from_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U32FromBits),
}
.start_end(pos.0, pos.1),
),
"u16_from_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U16FromBits),
}
.start_end(pos.0, pos.1),
),
"u8_from_bits" => symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::Flat(FlatEmbed::U8FromBits),
}
.start_end(pos.0, pos.1),
),
s => {
return Err(CompileErrorInner::ImportError(
Error::new(format!("Embed {} not found", s))
.with_pos(Some(pos)),
)
.in_file(&location)
.into())
}
}
}
}
_ => {
for symbol in &from.value.symbols {
match resolver {
Some(res) => {
match res
.resolve(location.clone(), module_id.to_path_buf())
{
Ok((source, new_location)) => {
match modules.get(&new_location) {
Some(_) => {}
None => {
let source = arena.alloc(source);
let compiled = compile_module::<T, E>(
source,
new_location.clone(),
resolver,
modules,
&arena,
)?;
assert!(modules
.insert(
new_location.clone(),
compiled
)
.is_none());
}
};
symbols.push(
SymbolDeclaration {
id: Some(symbol.get_alias()),
symbol: Symbol::There(
SymbolImport::with_id_in_module(
symbol.id,
new_location,
)
.start_end(pos.0, pos.1),
),
}
.start_end(pos.0, pos.1),
);
}
Err(err) => {
return Err(CompileErrorInner::ImportError(
err.into().with_pos(Some(pos)),
)
.in_file(&location)
.into());
}
}
}
None => {
return Err(CompileErrorInner::from(Error::new(
"Cannot resolve import without a resolver",
))
.in_file(&location)
.into());
}
}
}
}
}
}
_ => symbols.push(symbol),
},
_ => unreachable!(),
} }
} }
Ok(Module::with_symbols(symbols)) Ok(Module::with_symbols(symbols))
} }
fn resolve<'ast, T: Field, E: Into<Error>>(
import: CanonicalImportNode<'ast>,
location: &Path,
resolver: Option<&dyn Resolver<E>>,
modules: &mut HashMap<OwnedModuleId, Module<'ast>>,
arena: &'ast Arena<String>,
) -> Result<SymbolDeclarationNode<'ast>, CompileErrors> {
let pos = import.pos();
let module_id = import.value.source;
let symbol = import.value.id;
let symbol_declaration = match module_id.to_str().unwrap() {
"EMBED" => match symbol.id {
#[cfg(feature = "bellman")]
"sha256round" => {
if T::id() != Bn128Field::id() {
return Err(CompileErrorInner::ImportError(
Error::new(format!(
"Embed sha256round cannot be used with curve {}",
T::name()
))
.with_pos(Some(pos)),
)
.in_file(location)
.into());
} else {
SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::Sha256Round),
}
}
}
"unpack" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::Unpack),
},
"u64_to_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U64ToBits),
},
"u32_to_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U32ToBits),
},
"u16_to_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U16ToBits),
},
"u8_to_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U8ToBits),
},
"u64_from_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U64FromBits),
},
"u32_from_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U32FromBits),
},
"u16_from_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U16FromBits),
},
"u8_from_bits" => SymbolDeclaration {
id: symbol.get_alias(),
symbol: Symbol::Flat(FlatEmbed::U8FromBits),
},
s => {
return Err(CompileErrorInner::ImportError(
Error::new(format!("Embed {} not found", s)).with_pos(Some(pos)),
)
.in_file(location)
.into());
}
},
_ => match resolver {
Some(res) => match res.resolve(location.to_path_buf(), module_id.to_path_buf()) {
Ok((source, new_location)) => {
let alias = symbol.alias.unwrap_or(
module_id
.file_stem()
.ok_or_else(|| {
CompileErrors::from(
CompileErrorInner::ImportError(Error::new(format!(
"Could not determine alias for import {}",
module_id.display()
)))
.in_file(location),
)
})?
.to_str()
.unwrap(),
);
match modules.get(&new_location) {
Some(_) => {}
None => {
let source = arena.alloc(source);
let compiled = compile_module::<T, E>(
source,
new_location.clone(),
resolver,
modules,
&arena,
)?;
assert!(modules.insert(new_location.clone(), compiled).is_none());
}
};
SymbolDeclaration {
id: &alias,
symbol: Symbol::There(
SymbolImport::with_id_in_module(symbol.id, new_location)
.start_end(pos.0, pos.1),
),
}
}
Err(err) => {
return Err(
CompileErrorInner::ImportError(err.into().with_pos(Some(pos)))
.in_file(location)
.into(),
);
}
},
None => {
return Err(CompileErrorInner::from(Error::new(
"Cannot resolve import without a resolver",
))
.in_file(location)
.into());
}
},
};
Ok(symbol_declaration.start_end(pos.0, pos.1))
}
} }

View file

@ -453,24 +453,23 @@ impl<'ast, T: Field> Checker<'ast, T> {
let pos = declaration.pos(); let pos = declaration.pos();
let declaration = declaration.value; let declaration = declaration.value;
let declaration_id = declaration.id.unwrap();
match declaration.symbol.clone() { match declaration.symbol.clone() {
Symbol::Here(SymbolDefinition::Struct(t)) => { Symbol::Here(SymbolDefinition::Struct(t)) => {
match self.check_struct_type_declaration( match self.check_struct_type_declaration(
declaration_id.to_string(), declaration.id.to_string(),
t.clone(), t.clone(),
module_id, module_id,
state, state,
) { ) {
Ok(ty) => { Ok(ty) => {
match symbol_unifier.insert_type(declaration_id) { match symbol_unifier.insert_type(declaration.id) {
false => errors.push( false => errors.push(
ErrorInner { ErrorInner {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id declaration.id
), ),
} }
.in_file(module_id), .in_file(module_id),
@ -481,7 +480,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
.types .types
.entry(module_id.to_path_buf()) .entry(module_id.to_path_buf())
.or_default() .or_default()
.insert(declaration_id.to_string(), ty) .insert(declaration.id.to_string(), ty)
.is_none()); .is_none());
} }
}; };
@ -493,31 +492,31 @@ impl<'ast, T: Field> Checker<'ast, T> {
} }
} }
Symbol::Here(SymbolDefinition::Constant(c)) => { Symbol::Here(SymbolDefinition::Constant(c)) => {
match self.check_constant_definition(declaration_id, c, module_id, state) { match self.check_constant_definition(declaration.id, c, module_id, state) {
Ok(c) => { Ok(c) => {
match symbol_unifier.insert_constant(declaration_id) { match symbol_unifier.insert_constant(declaration.id) {
false => errors.push( false => errors.push(
ErrorInner { ErrorInner {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id declaration.id
), ),
} }
.in_file(module_id), .in_file(module_id),
), ),
true => { true => {
constants constants
.insert(declaration_id, TypedConstantSymbol::Here(c.clone())); .insert(declaration.id, TypedConstantSymbol::Here(c.clone()));
self.insert_into_scope(Variable::with_id_and_type( self.insert_into_scope(Variable::with_id_and_type(
declaration_id, declaration.id,
c.get_type(), c.get_type(),
)); ));
assert!(state assert!(state
.constants .constants
.entry(module_id.to_path_buf()) .entry(module_id.to_path_buf())
.or_default() .or_default()
.insert(declaration_id, c.get_type()) .insert(declaration.id, c.get_type())
.is_none()); .is_none());
} }
}; };
@ -531,14 +530,14 @@ impl<'ast, T: Field> Checker<'ast, T> {
match self.check_function(f, module_id, state) { match self.check_function(f, module_id, state) {
Ok(funct) => { Ok(funct) => {
match symbol_unifier match symbol_unifier
.insert_function(declaration_id, funct.signature.clone()) .insert_function(declaration.id, funct.signature.clone())
{ {
false => errors.push( false => errors.push(
ErrorInner { ErrorInner {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id declaration.id
), ),
} }
.in_file(module_id), .in_file(module_id),
@ -549,14 +548,14 @@ impl<'ast, T: Field> Checker<'ast, T> {
self.functions.insert( self.functions.insert(
DeclarationFunctionKey::with_location( DeclarationFunctionKey::with_location(
module_id.to_path_buf(), module_id.to_path_buf(),
declaration_id, declaration.id,
) )
.signature(funct.signature.clone()), .signature(funct.signature.clone()),
); );
functions.insert( functions.insert(
DeclarationFunctionKey::with_location( DeclarationFunctionKey::with_location(
module_id.to_path_buf(), module_id.to_path_buf(),
declaration_id, declaration.id,
) )
.signature(funct.signature.clone()), .signature(funct.signature.clone()),
TypedFunctionSymbol::Here(funct), TypedFunctionSymbol::Here(funct),
@ -613,7 +612,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
let t = match t { let t = match t {
DeclarationType::Struct(t) => DeclarationType::Struct(DeclarationStructType { DeclarationType::Struct(t) => DeclarationType::Struct(DeclarationStructType {
location: Some(StructLocation { location: Some(StructLocation {
name: declaration_id.into(), name: declaration.id.into(),
module: module_id.to_path_buf() module: module_id.to_path_buf()
}), }),
..t ..t
@ -622,7 +621,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
}; };
// we imported a type, so the symbol it gets bound to should not already exist // we imported a type, so the symbol it gets bound to should not already exist
match symbol_unifier.insert_type(declaration_id) { match symbol_unifier.insert_type(declaration.id) {
false => { false => {
errors.push(Error { errors.push(Error {
module_id: module_id.to_path_buf(), module_id: module_id.to_path_buf(),
@ -630,7 +629,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id, declaration.id,
), ),
}}); }});
} }
@ -640,10 +639,10 @@ impl<'ast, T: Field> Checker<'ast, T> {
.types .types
.entry(module_id.to_path_buf()) .entry(module_id.to_path_buf())
.or_default() .or_default()
.insert(declaration_id.to_string(), t); .insert(declaration.id.to_string(), t);
} }
(0, None, Some(ty)) => { (0, None, Some(ty)) => {
match symbol_unifier.insert_constant(declaration_id) { match symbol_unifier.insert_constant(declaration.id) {
false => { false => {
errors.push(Error { errors.push(Error {
module_id: module_id.to_path_buf(), module_id: module_id.to_path_buf(),
@ -651,19 +650,19 @@ impl<'ast, T: Field> Checker<'ast, T> {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id, declaration.id,
), ),
}}); }});
} }
true => { true => {
constants.insert(declaration_id, TypedConstantSymbol::There(import.module_id.to_path_buf(), symbol_id)); constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id.to_path_buf(), symbol_id));
self.insert_into_scope(Variable::with_id_and_type(declaration_id, ty.clone())); self.insert_into_scope(Variable::with_id_and_type(declaration.id, ty.clone()));
state state
.constants .constants
.entry(module_id.to_path_buf()) .entry(module_id.to_path_buf())
.or_default() .or_default()
.insert(declaration_id, ty); .insert(declaration.id, ty);
} }
}; };
} }
@ -680,20 +679,20 @@ impl<'ast, T: Field> Checker<'ast, T> {
_ => { _ => {
for candidate in function_candidates { for candidate in function_candidates {
match symbol_unifier.insert_function(declaration_id, candidate.signature.clone()) { match symbol_unifier.insert_function(declaration.id, candidate.signature.clone()) {
false => { false => {
errors.push(ErrorInner { errors.push(ErrorInner {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id, declaration.id,
), ),
}.in_file(module_id)); }.in_file(module_id));
}, },
true => {} true => {}
}; };
let local_key = candidate.clone().id(declaration_id).module(module_id.to_path_buf()); let local_key = candidate.clone().id(declaration.id).module(module_id.to_path_buf());
self.functions.insert(local_key.clone()); self.functions.insert(local_key.clone());
functions.insert( functions.insert(
@ -711,14 +710,14 @@ impl<'ast, T: Field> Checker<'ast, T> {
}; };
} }
Symbol::Flat(funct) => { Symbol::Flat(funct) => {
match symbol_unifier.insert_function(declaration_id, funct.signature()) { match symbol_unifier.insert_function(declaration.id, funct.signature()) {
false => { false => {
errors.push( errors.push(
ErrorInner { ErrorInner {
pos: Some(pos), pos: Some(pos),
message: format!( message: format!(
"{} conflicts with another symbol", "{} conflicts with another symbol",
declaration_id declaration.id
), ),
} }
.in_file(module_id), .in_file(module_id),
@ -728,11 +727,11 @@ impl<'ast, T: Field> Checker<'ast, T> {
}; };
self.functions.insert( self.functions.insert(
DeclarationFunctionKey::with_location(module_id.to_path_buf(), declaration_id) DeclarationFunctionKey::with_location(module_id.to_path_buf(), declaration.id)
.signature(funct.signature()), .signature(funct.signature()),
); );
functions.insert( functions.insert(
DeclarationFunctionKey::with_location(module_id.to_path_buf(), declaration_id) DeclarationFunctionKey::with_location(module_id.to_path_buf(), declaration.id)
.signature(funct.signature()), .signature(funct.signature()),
TypedFunctionSymbol::Flat(funct), TypedFunctionSymbol::Flat(funct),
); );
@ -3267,7 +3266,7 @@ mod tests {
let foo: Module = Module { let foo: Module = Module {
symbols: vec![SymbolDeclaration { symbols: vec![SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock()], .mock()],
@ -3275,7 +3274,7 @@ mod tests {
let bar: Module = Module { let bar: Module = Module {
symbols: vec![SymbolDeclaration { symbols: vec![SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::There(SymbolImport::with_id_in_module("main", "foo").mock()), symbol: Symbol::There(SymbolImport::with_id_in_module("main", "foo").mock()),
} }
.mock()], .mock()],
@ -3323,12 +3322,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
@ -3401,12 +3400,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(f0)), symbol: Symbol::Here(SymbolDefinition::Function(f0)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(f1)), symbol: Symbol::Here(SymbolDefinition::Function(f1)),
} }
.mock(), .mock(),
@ -3438,12 +3437,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
@ -3490,12 +3489,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
@ -3527,12 +3526,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(function1())), symbol: Symbol::Here(SymbolDefinition::Function(function1())),
} }
.mock(), .mock(),
@ -3576,12 +3575,12 @@ mod tests {
let module: Module = Module { let module: Module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), symbol: Symbol::Here(SymbolDefinition::Struct(struct0())),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Struct(struct1())), symbol: Symbol::Here(SymbolDefinition::Struct(struct1())),
} }
.mock(), .mock(),
@ -3612,12 +3611,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { fields: vec![] }.mock(), StructDefinition { fields: vec![] }.mock(),
)), )),
@ -3653,7 +3652,7 @@ mod tests {
// should fail // should fail
let bar = Module::with_symbols(vec![SymbolDeclaration { let bar = Module::with_symbols(vec![SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock()]); .mock()]);
@ -3661,14 +3660,14 @@ mod tests {
let main = Module { let main = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::There( symbol: Symbol::There(
SymbolImport::with_id_in_module("main", "bar").mock(), SymbolImport::with_id_in_module("main", "bar").mock(),
), ),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), symbol: Symbol::Here(SymbolDefinition::Struct(struct0())),
} }
.mock(), .mock(),
@ -3701,7 +3700,7 @@ mod tests {
// should fail // should fail
let bar = Module::with_symbols(vec![SymbolDeclaration { let bar = Module::with_symbols(vec![SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(function0())), symbol: Symbol::Here(SymbolDefinition::Function(function0())),
} }
.mock()]); .mock()]);
@ -3709,12 +3708,12 @@ mod tests {
let main = Module { let main = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), symbol: Symbol::Here(SymbolDefinition::Struct(struct0())),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::There( symbol: Symbol::There(
SymbolImport::with_id_in_module("main", "bar").mock(), SymbolImport::with_id_in_module("main", "bar").mock(),
), ),
@ -3928,12 +3927,12 @@ mod tests {
let symbols = vec![ let symbols = vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("bar"), id: "bar",
symbol: Symbol::Here(SymbolDefinition::Function(bar)), symbol: Symbol::Here(SymbolDefinition::Function(bar)),
} }
.mock(), .mock(),
@ -4040,17 +4039,17 @@ mod tests {
let symbols = vec![ let symbols = vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("bar"), id: "bar",
symbol: Symbol::Here(SymbolDefinition::Function(bar)), symbol: Symbol::Here(SymbolDefinition::Function(bar)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main)), symbol: Symbol::Here(SymbolDefinition::Function(main)),
} }
.mock(), .mock(),
@ -4430,12 +4429,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main)), symbol: Symbol::Here(SymbolDefinition::Function(main)),
} }
.mock(), .mock(),
@ -4516,12 +4515,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main)), symbol: Symbol::Here(SymbolDefinition::Function(main)),
} }
.mock(), .mock(),
@ -4631,12 +4630,12 @@ mod tests {
let module = Module { let module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo)), symbol: Symbol::Here(SymbolDefinition::Function(foo)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main)), symbol: Symbol::Here(SymbolDefinition::Function(main)),
} }
.mock(), .mock(),
@ -4929,12 +4928,12 @@ mod tests {
let symbols = vec![ let symbols = vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main1)), symbol: Symbol::Here(SymbolDefinition::Function(main1)),
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main2)), symbol: Symbol::Here(SymbolDefinition::Function(main2)),
} }
.mock(), .mock(),
@ -5040,7 +5039,7 @@ mod tests {
) -> (Checker<Bn128Field>, State<Bn128Field>) { ) -> (Checker<Bn128Field>, State<Bn128Field>) {
let module: Module = Module { let module: Module = Module {
symbols: vec![SymbolDeclaration { symbols: vec![SymbolDeclaration {
id: Some("Foo"), id: "Foo",
symbol: Symbol::Here(SymbolDefinition::Struct(s.mock())), symbol: Symbol::Here(SymbolDefinition::Struct(s.mock())),
} }
.mock()], .mock()],
@ -5174,7 +5173,7 @@ mod tests {
let module: Module = Module { let module: Module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("Foo"), id: "Foo",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5188,7 +5187,7 @@ mod tests {
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("Bar"), id: "Bar",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5242,7 +5241,7 @@ mod tests {
let module: Module = Module { let module: Module = Module {
symbols: vec![SymbolDeclaration { symbols: vec![SymbolDeclaration {
id: Some("Bar"), id: "Bar",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5274,7 +5273,7 @@ mod tests {
let module: Module = Module { let module: Module = Module {
symbols: vec![SymbolDeclaration { symbols: vec![SymbolDeclaration {
id: Some("Foo"), id: "Foo",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5308,7 +5307,7 @@ mod tests {
let module: Module = Module { let module: Module = Module {
symbols: vec![ symbols: vec![
SymbolDeclaration { SymbolDeclaration {
id: Some("Foo"), id: "Foo",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5322,7 +5321,7 @@ mod tests {
} }
.mock(), .mock(),
SymbolDeclaration { SymbolDeclaration {
id: Some("Bar"), id: "Bar",
symbol: Symbol::Here(SymbolDefinition::Struct( symbol: Symbol::Here(SymbolDefinition::Struct(
StructDefinition { StructDefinition {
fields: vec![StructDefinitionField { fields: vec![StructDefinitionField {
@ -5800,17 +5799,17 @@ mod tests {
let m = Module::with_symbols(vec![ let m = Module::with_symbols(vec![
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo_field)), symbol: Symbol::Here(SymbolDefinition::Function(foo_field)),
} }
.mock(), .mock(),
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some("foo"), id: "foo",
symbol: Symbol::Here(SymbolDefinition::Function(foo_u32)), symbol: Symbol::Here(SymbolDefinition::Function(foo_u32)),
} }
.mock(), .mock(),
absy::SymbolDeclaration { absy::SymbolDeclaration {
id: Some("main"), id: "main",
symbol: Symbol::Here(SymbolDefinition::Function(main)), symbol: Symbol::Here(SymbolDefinition::Function(main)),
} }
.mock(), .mock(),