feat: remove plutus v1,v2 from aiken.toml closes #1032

This commit is contained in:
rvcas
2024-12-25 22:52:08 -05:00
parent 3355b477e2
commit c1871768f8
10 changed files with 279 additions and 367 deletions

View File

@@ -4,7 +4,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum PlutusVersion {
#[serde(skip_deserializing)]
V1,
#[serde(skip_deserializing)]
V2,
#[default]
V3,

View File

@@ -1,4 +1,6 @@
use crate::{github::repo::LatestRelease, package_name::PackageName, paths, Error};
use crate::{
error::TomlLoadingContext, github::repo::LatestRelease, package_name::PackageName, paths, Error,
};
use aiken_lang::{
ast::{Annotation, ByteArrayFormatPreference, ModuleConstant, Span, UntypedDefinition},
expr::UntypedExpr,
@@ -343,6 +345,7 @@ impl Config {
})?;
let result: Self = toml::from_str(&raw_config).map_err(|e| Error::TomlLoading {
ctx: TomlLoadingContext::Project,
path: config_path.clone(),
src: raw_config.clone(),
named: NamedSource::new(config_path.display().to_string(), raw_config).into(),
@@ -351,7 +354,7 @@ impl Config {
start: range.start,
end: range.end,
}),
help: e.to_string(),
help: e.message().to_string(),
})?;
Ok(result)

View File

@@ -7,7 +7,7 @@ use tokio::time::Instant;
use crate::{
config::{Config, Dependency},
error::Error,
error::{Error, TomlLoadingContext},
package_name::PackageName,
paths,
telemetry::{DownloadSource, Event, EventListener},
@@ -44,6 +44,7 @@ impl LocalPackages {
let src = fs::read_to_string(&path)?;
let result: Self = toml::from_str(&src).map_err(|e| Error::TomlLoading {
ctx: TomlLoadingContext::Package,
path: path.clone(),
src: src.clone(),
named: NamedSource::new(path.display().to_string(), src).into(),
@@ -52,7 +53,7 @@ impl LocalPackages {
start: range.start,
end: range.end,
}),
help: e.to_string(),
help: e.message().to_string(),
})?;
Ok(result)

View File

@@ -10,7 +10,7 @@ use std::{
use crate::{
config::{Config, Dependency, Platform},
error::Error,
error::{Error, TomlLoadingContext},
package_name::PackageName,
paths,
telemetry::{Event, EventListener},
@@ -47,6 +47,7 @@ impl Manifest {
let toml = fs::read_to_string(&manifest_path)?;
let manifest: Self = toml::from_str(&toml).map_err(|e| Error::TomlLoading {
ctx: TomlLoadingContext::Manifest,
path: manifest_path.clone(),
src: toml.clone(),
named: NamedSource::new(manifest_path.display().to_string(), toml).into(),
@@ -55,7 +56,7 @@ impl Manifest {
start: range.start,
end: range.end,
}),
help: e.to_string(),
help: e.message().to_string(),
})?;
// If the config is unchanged since the manifest was written then it is up

View File

@@ -15,12 +15,28 @@ use owo_colors::{
Stream::{Stderr, Stdout},
};
use std::{
fmt::{Debug, Display},
fmt::{self, Debug, Display},
io,
path::{Path, PathBuf},
};
use zip::result::ZipError;
pub enum TomlLoadingContext {
Project,
Manifest,
Package,
}
impl fmt::Display for TomlLoadingContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TomlLoadingContext::Project => write!(f, "project"),
TomlLoadingContext::Manifest => write!(f, "manifest"),
TomlLoadingContext::Package => write!(f, "package"),
}
}
}
#[allow(dead_code)]
#[derive(thiserror::Error)]
pub enum Error {
@@ -58,8 +74,9 @@ pub enum Error {
#[error(transparent)]
Module(#[from] ast::Error),
#[error("{help}")]
#[error("I could not load the {ctx} config file.")]
TomlLoading {
ctx: TomlLoadingContext,
path: PathBuf,
src: String,
named: Box<NamedSource<String>>,
@@ -372,7 +389,7 @@ impl Diagnostic for Error {
Error::NoDefaultEnvironment { .. } => Some(Box::new(
"Environment module names are free, but there must be at least one named 'default.ak'.",
)),
Error::TomlLoading { .. } => None,
Error::TomlLoading { help, .. } => Some(Box::new(help)),
Error::Format { .. } => None,
Error::TestFailure { .. } => None,
Error::Http(_) => None,

View File

@@ -64,16 +64,16 @@ impl Export {
})
.collect::<Result<_, _>>()?;
let program = generator
.generate_raw(&func.body, &func.arguments, &module.name)
.to_debruijn()
.unwrap();
let program = match plutus_version {
PlutusVersion::V1 => SerializableProgram::PlutusV1Program,
PlutusVersion::V2 => SerializableProgram::PlutusV2Program,
PlutusVersion::V3 => SerializableProgram::PlutusV3Program,
}(
generator
.generate_raw(&func.body, &func.arguments, &module.name)
.to_debruijn()
.unwrap(),
);
PlutusVersion::V1 => SerializableProgram::PlutusV1Program(program),
PlutusVersion::V2 => SerializableProgram::PlutusV2Program(program),
PlutusVersion::V3 => SerializableProgram::PlutusV3Program(program),
};
Ok(Export {
name: format!("{}.{}", &module.name, &func.name),