Merge pull request #316 from aiken-lang/cip-0057-blueprints

Blueprints (CIP-0057) as build artifacts
This commit is contained in:
Matthias Benkort
2023-01-31 17:45:56 +01:00
committed by GitHub
46 changed files with 2255 additions and 451 deletions

View File

@@ -988,7 +988,7 @@ pub fn convert_constants_to_data(constants: Vec<UplcConstant>) -> Vec<UplcConsta
new_constants
}
pub fn wrap_validator_args(term: Term<Name>, arguments: Vec<TypedArg>) -> Term<Name> {
pub fn wrap_validator_args(term: Term<Name>, arguments: &[TypedArg]) -> Term<Name> {
let mut term = term;
for arg in arguments.iter().rev() {
if !matches!(arg.tipo.get_uplc_type(), UplcType::Data) {

View File

@@ -1,12 +1,6 @@
use std::{cell::RefCell, collections::HashMap, sync::Arc};
use strum::IntoEnumIterator;
use uplc::builtins::DefaultFunction;
use crate::{
ast::{Arg, ArgName, CallArg, Function, ModuleKind, Span, TypedFunction, UnOp},
builder::FunctionAccessKey,
ast::{Arg, ArgName, CallArg, Function, ModuleKind, Span, TypedDataType, TypedFunction, UnOp},
builder::{DataTypeKey, FunctionAccessKey},
expr::TypedExpr,
tipo::{
fields::FieldMap, Type, TypeConstructor, TypeInfo, TypeVar, ValueConstructor,
@@ -14,6 +8,10 @@ use crate::{
},
IdGenerator,
};
use indexmap::IndexMap;
use std::{cell::RefCell, collections::HashMap, sync::Arc};
use strum::IntoEnumIterator;
use uplc::builtins::DefaultFunction;
pub const BYTE_ARRAY: &str = "ByteArray";
pub const BOOL: &str = "Bool";
@@ -533,8 +531,8 @@ pub fn from_default_function(
})
}
pub fn prelude_functions(id_gen: &IdGenerator) -> HashMap<FunctionAccessKey, TypedFunction> {
let mut functions = HashMap::new();
pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, TypedFunction> {
let mut functions = IndexMap::new();
// /// Negate the argument. Useful for map/fold and pipelines.
// pub fn not(self: Bool) -> Bool {
@@ -800,6 +798,22 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> HashMap<FunctionAccessKey, Typ
functions
}
pub fn prelude_data_types(id_gen: &IdGenerator) -> IndexMap<DataTypeKey, TypedDataType> {
let mut data_types = IndexMap::new();
// Option
let option_data_type = TypedDataType::option(generic_var(id_gen.next()));
data_types.insert(
DataTypeKey {
module_name: "".to_string(),
defined_type: "Option".to_string(),
},
option_data_type,
);
data_types
}
pub fn int() -> Arc<Type> {
Arc::new(Type::App {
public: true,

View File

@@ -466,7 +466,7 @@ Perhaps, try the following:
#[diagnostic(code("unknown::module"))]
#[diagnostic(help(
"{}",
suggest_neighbor(name, imported_modules.iter(), "Did you forget to import it?")
suggest_neighbor(name, imported_modules.iter(), "Did you forget to add a package as dependency?")
))]
UnknownModule {
#[label]

View File

@@ -80,7 +80,6 @@ impl UntypedModule {
for def in consts.into_iter().chain(not_consts) {
let definition = infer_definition(def, &name, &mut hydrators, &mut environment, kind)?;
definitions.push(definition);
}
@@ -339,6 +338,7 @@ fn infer_definition(
label,
annotation,
location,
doc,
..
},
t,
@@ -348,7 +348,7 @@ fn infer_definition(
annotation,
location,
tipo: t.clone(),
doc: None,
doc,
}
},
)

View File

@@ -39,12 +39,12 @@ use crate::{
IdGenerator,
};
#[derive(Clone)]
pub struct CodeGenerator<'a> {
defined_functions: IndexMap<FunctionAccessKey, ()>,
functions: &'a IndexMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a IndexMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a IndexMap<DataTypeKey, &'a TypedDataType>,
module_types: &'a IndexMap<String, TypeInfo>,
functions: IndexMap<FunctionAccessKey, &'a TypedFunction>,
data_types: IndexMap<DataTypeKey, &'a TypedDataType>,
module_types: IndexMap<&'a String, &'a TypeInfo>,
id_gen: IdGenerator,
needs_field_access: bool,
used_data_assert_on_list: bool,
@@ -53,15 +53,13 @@ pub struct CodeGenerator<'a> {
impl<'a> CodeGenerator<'a> {
pub fn new(
functions: &'a IndexMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a IndexMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a IndexMap<DataTypeKey, &'a TypedDataType>,
module_types: &'a IndexMap<String, TypeInfo>,
functions: IndexMap<FunctionAccessKey, &'a TypedFunction>,
data_types: IndexMap<DataTypeKey, &'a TypedDataType>,
module_types: IndexMap<&'a String, &'a TypeInfo>,
) -> Self {
CodeGenerator {
defined_functions: IndexMap::new(),
functions,
// type_aliases,
data_types,
module_types,
id_gen: IdGenerator::new(),
@@ -73,14 +71,14 @@ impl<'a> CodeGenerator<'a> {
pub fn generate(
&mut self,
body: TypedExpr,
arguments: Vec<TypedArg>,
body: &TypedExpr,
arguments: &[TypedArg],
wrap_as_validator: bool,
) -> Program<Name> {
let mut ir_stack = vec![];
let scope = vec![self.id_gen.next()];
self.build_ir(&body, &mut ir_stack, scope);
self.build_ir(body, &mut ir_stack, scope);
self.define_ir(&mut ir_stack);
@@ -2865,7 +2863,7 @@ impl<'a> CodeGenerator<'a> {
variant_name: String::new(),
};
let function = self.functions.get(&non_variant_function_key).unwrap();
let function = *self.functions.get(&non_variant_function_key).unwrap();
let mut func_ir = vec![];
@@ -3355,7 +3353,7 @@ impl<'a> CodeGenerator<'a> {
count,
scope,
} => {
if check_replaceable_opaque_type(&tipo, self.data_types) {
if check_replaceable_opaque_type(&tipo, &self.data_types) {
indices_to_remove.push(index);
} else {
let mut replaced_type = tipo.clone();
@@ -3377,7 +3375,7 @@ impl<'a> CodeGenerator<'a> {
let record = ir_stack[index + 1].clone();
let record_type = record.tipo();
if let Some(record_type) = record_type {
if check_replaceable_opaque_type(&record_type, self.data_types) {
if check_replaceable_opaque_type(&record_type, &self.data_types) {
indices_to_remove.push(index);
} else {
let mut replaced_type = tipo.clone();
@@ -3408,7 +3406,7 @@ impl<'a> CodeGenerator<'a> {
let record = ir_stack[index + 1].clone();
let record_type = record.tipo();
if let Some(record_type) = record_type {
if check_replaceable_opaque_type(&record_type, self.data_types) {
if check_replaceable_opaque_type(&record_type, &self.data_types) {
ir_stack[index] = Air::Let {
scope,
name: indices[0].1.clone(),