From fb8620d6354a129bcefd87a629a6f1d5924a9d47 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:12:30 -0800 Subject: [PATCH] Support for doubly nested external records in function signature --- compiler/ast/src/passes/visitor.rs | 1 - compiler/ast/src/stub/function_stub.rs | 23 +++++++++++++---------- compiler/ast/src/types/struct_type.rs | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/ast/src/passes/visitor.rs b/compiler/ast/src/passes/visitor.rs index 53e94b03a3..72b4fa237d 100644 --- a/compiler/ast/src/passes/visitor.rs +++ b/compiler/ast/src/passes/visitor.rs @@ -20,7 +20,6 @@ use crate::*; - /// A Visitor trait for expressions in the AST. pub trait ExpressionVisitor<'a> { type AdditionalInput: Default; diff --git a/compiler/ast/src/stub/function_stub.rs b/compiler/ast/src/stub/function_stub.rs index 47ecec0fa1..3cdac4b409 100644 --- a/compiler/ast/src/stub/function_stub.rs +++ b/compiler/ast/src/stub/function_stub.rs @@ -35,7 +35,7 @@ use crate::{ }; use leo_span::{sym, Span, Symbol}; -use crate::Type::{Struct}; +use crate::Type::Struct; use itertools::Itertools; use serde::{Deserialize, Serialize}; use snarkvm::{ @@ -137,14 +137,15 @@ impl FunctionStub { span: Default::default(), id: Default::default(), })], - ValueType::ExternalRecord(loc) => vec![Output::External(External { - // TODO - identifier: Identifier::new(Symbol::intern("dummy"), Default::default()), - program_name: ProgramId::from(loc.program_id()).name, - record: Identifier::from(loc.resource()), - span: Default::default(), - id: Default::default(), - })], + ValueType::ExternalRecord(loc) => { + vec![Output::External(External { + identifier: Identifier::new(Symbol::intern("dummy"), Default::default()), + program_name: ProgramId::from(loc.program_id()).name, + record: Identifier::from(loc.resource()), + span: Default::default(), + id: Default::default(), + })] + } ValueType::Future(_) => Vec::new(), // Don't include futures in the output signature }) .collect_vec() @@ -153,7 +154,9 @@ impl FunctionStub { .iter() .map(|output| match output { Output::Internal(output) => output.type_.clone(), - Output::External(output) => Type::Identifier(output.record), + Output::External(output) => { + Type::Struct(StructType { id: output.record, external: Some(output.program_name.name) }) + } }) .collect_vec(); let output_type = match output_vec.len() { diff --git a/compiler/ast/src/types/struct_type.rs b/compiler/ast/src/types/struct_type.rs index 1fc8a6cf32..7da58bc3ff 100644 --- a/compiler/ast/src/types/struct_type.rs +++ b/compiler/ast/src/types/struct_type.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Identifier}; +use crate::Identifier; use leo_span::Symbol; use serde::{Deserialize, Serialize};