Skip to content

Commit

Permalink
chore: clean up winterfell deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Mar 16, 2024
1 parent bbce102 commit b0a8361
Show file tree
Hide file tree
Showing 89 changed files with 241 additions and 593 deletions.
3 changes: 2 additions & 1 deletion air/src/constraints/chiplets/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use crate::{
BITWISE_A_COL_IDX, BITWISE_A_COL_RANGE, BITWISE_B_COL_IDX, BITWISE_B_COL_RANGE,
BITWISE_OUTPUT_COL_IDX, BITWISE_PREV_OUTPUT_COL_IDX, BITWISE_SELECTOR_COL_IDX,
},
utils::{are_equal, binary_not, collections::*, is_binary, is_zero, EvaluationResult},
utils::{are_equal, binary_not, is_binary, is_zero, EvaluationResult},
ONE, ZERO,
};
use alloc::vec::Vec;
use winter_air::TransitionConstraintDegree;

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/chiplets/hasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use crate::{
},
HASHER_NODE_INDEX_COL_IDX, HASHER_SELECTOR_COL_RANGE, HASHER_STATE_COL_RANGE,
},
utils::{are_equal, binary_not, collections::*, is_binary, EvaluationResult},
utils::{are_equal, binary_not, is_binary, EvaluationResult},
ONE, ZERO,
};
use alloc::vec::Vec;

#[cfg(test)]
mod tests;
Expand Down
2 changes: 1 addition & 1 deletion air/src/constraints/chiplets/hasher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::{
};
use crate::{
trace::chiplets::hasher::{Selectors, LINEAR_HASH, STATE_WIDTH},
utils::collections::*,
Felt, TRACE_WIDTH,
};
use alloc::vec::Vec;
use rand_utils::rand_array;
use vm_core::chiplets::hasher::apply_round;
use winter_air::EvaluationFrame;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/chiplets/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::{
MEMORY_D0_COL_IDX, MEMORY_D1_COL_IDX, MEMORY_D_INV_COL_IDX, MEMORY_TRACE_OFFSET,
MEMORY_V_COL_RANGE,
},
utils::{binary_not, collections::*, is_binary, EvaluationResult},
utils::{binary_not, is_binary, EvaluationResult},
};
use alloc::vec::Vec;
use winter_air::TransitionConstraintDegree;

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/chiplets/memory/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::trace::{
},
TRACE_WIDTH,
};
use crate::{chiplets::memory, utils::collections::*, Felt, FieldElement, ONE, ZERO};
use crate::{chiplets::memory, Felt, FieldElement, ONE, ZERO};
use alloc::vec::Vec;
use rand_utils::rand_value;

// UNIT TESTS
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/chiplets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::super::{
EvaluationFrame, Felt, FieldElement, TransitionConstraintDegree, CHIPLETS_OFFSET,
};
use crate::utils::{are_equal, binary_not, collections::*, is_binary};
use crate::utils::{are_equal, binary_not, is_binary};
use alloc::vec::Vec;

mod bitwise;
mod hasher;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use crate::{
chiplets::ChipletsFrameExt,
constraints::MainFrameExt,
trace::range::{B_RANGE_COL_IDX, M_COL_IDX, V_COL_IDX},
utils::{are_equal, collections::*},
utils::are_equal,
Assertion, EvaluationFrame, Felt, FieldElement, TransitionConstraintDegree,
};
use alloc::vec::Vec;
use vm_core::{ExtensionOf, ZERO};
use winter_air::AuxTraceRandElements;

Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/stack/field_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::{op_flags::OpFlags, EvaluationFrame, FieldElement, TransitionConstraintDegree};
use crate::{
stack::EvaluationFrameExt,
utils::{are_equal, collections::*, is_binary},
utils::{are_equal, is_binary},
};
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
6 changes: 2 additions & 4 deletions air/src/constraints/stack/io_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::{op_flags::OpFlags, EvaluationFrame, FieldElement, TransitionConstraintDegree};
use crate::{
stack::EvaluationFrameExt,
utils::{are_equal, collections::*},
};
use crate::{stack::EvaluationFrameExt, utils::are_equal};
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use super::super::{
STACK_AUX_TRACE_OFFSET, STACK_TRACE_OFFSET, ZERO,
};
use crate::decoder::{IS_CALL_FLAG_COL_IDX, IS_SYSCALL_FLAG_COL_IDX, USER_OP_HELPERS_OFFSET};
use crate::utils::{are_equal, collections::*, is_binary};
use crate::utils::{are_equal, is_binary};
use alloc::vec::Vec;
use vm_core::{stack::STACK_TOP_SIZE, StackOutputs};

pub mod field_ops;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/stack/overflow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{op_flags::OpFlags, EvaluationFrame, FieldElement, TransitionConstraintDegree};
use crate::{stack::EvaluationFrameExt, utils::collections::*};
use crate::stack::EvaluationFrameExt;
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/stack/stack_manipulation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::{op_flags::OpFlags, EvaluationFrame, FieldElement, TransitionConstraintDegree};
use crate::{
stack::EvaluationFrameExt,
utils::{are_equal, binary_not, collections::*},
utils::{are_equal, binary_not},
};
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
6 changes: 2 additions & 4 deletions air/src/constraints/stack/system_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::{op_flags::OpFlags, EvaluationFrame, FieldElement, TransitionConstraintDegree};
use crate::{
stack::EvaluationFrameExt,
utils::{are_equal, collections::*},
};
use crate::{stack::EvaluationFrameExt, utils::are_equal};
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
3 changes: 2 additions & 1 deletion air/src/constraints/stack/u32_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::{op_flags::OpFlags, EvaluationFrame, Felt, FieldElement, TransitionConstraintDegree};
use crate::{
stack::EvaluationFrameExt,
utils::{are_equal, collections::*, is_binary},
utils::{are_equal, is_binary},
};
use alloc::vec::Vec;

#[cfg(test)]
pub mod tests;
Expand Down
3 changes: 2 additions & 1 deletion air/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{trace::MIN_TRACE_LEN, utils::string::*};
use crate::trace::MIN_TRACE_LEN;
use alloc::string::String;
use core::fmt::{Display, Formatter};

// EXECUTION ERROR
Expand Down
9 changes: 6 additions & 3 deletions air/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

use alloc::vec::Vec;
use vm_core::{
utils::{collections::*, ByteReader, ByteWriter, Deserializable, Serializable},
utils::{ByteReader, ByteWriter, Deserializable, Serializable},
ExtensionOf, ProgramInfo, StackInputs, StackOutputs, ONE, ZERO,
};
use winter_air::{
Expand Down
5 changes: 2 additions & 3 deletions air/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use alloc::vec::Vec;
use vm_core::{
crypto::hash::{Blake3_192, Blake3_256, Hasher, Rpo256},
utils::{
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
},
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
};
use winter_air::proof::StarkProof;

Expand Down
2 changes: 1 addition & 1 deletion air/src/trace/main_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
CHIPLETS_OFFSET, CLK_COL_IDX, CTX_COL_IDX, DECODER_TRACE_OFFSET, FMP_COL_IDX, FN_HASH_OFFSET,
STACK_TRACE_OFFSET,
};
use crate::utils::collections::*;
use alloc::vec::Vec;
use core::ops::{Deref, Range};
use vm_core::{utils::range, Felt, ONE, ZERO};

Expand Down
7 changes: 2 additions & 5 deletions air/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use super::FieldElement;
use alloc::vec::Vec;
use core::ops::Range;
use vm_core::utils::{collections::*, range as create_range};

// RE-EXPORTS
// ================================================================================================
pub use vm_core::utils::{collections, string};
use vm_core::utils::range as create_range;

// BASIC CONSTRAINT OPERATORS
// ================================================================================================
Expand Down
5 changes: 1 addition & 4 deletions assembly/src/ast/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ impl Module {
where
P: AsRef<std::path::Path>,
{
use vm_core::utils::WriteAdapter;

let path = path.as_ref();
if let Some(dir) = path.parent() {
std::fs::create_dir_all(dir)?;
Expand All @@ -557,8 +555,7 @@ impl Module {
serialize_imports: true,
debug_info: true,
};
let mut adapter = WriteAdapter::new(file);
self.write_into_with_options(&mut adapter, options);
self.write_into_with_options(file, options);
Ok(())
}
Err(err) => Err(err),
Expand Down
22 changes: 15 additions & 7 deletions assembly/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
diagnostics::{
Diagnostic, IntoDiagnostic, NamedSource, Report, SourceCode, SourceFile, WrapErr,
},
library::{LibraryNamespace, LibraryPath, PathError},
library::{LibraryNamespace, LibraryPath},
};

/// The set of options which can be used to control the behavior of the [Compile] trait.
Expand Down Expand Up @@ -223,8 +223,10 @@ impl<'a> Compile for &'a [u8] {
#[inline(always)]
fn compile_with_opts(self, options: Options) -> Result<Box<Module>, Report> {
core::str::from_utf8(self)
.into_diagnostic()
.wrap_err("parsing failed: expected source code to be valid utf-8")
.map_err(|err| {
Report::from(crate::parser::ParsingError::from(err)).with_source_code(self.to_vec())
})
.wrap_err("parsing failed: invalid source code")
.and_then(|source| source.compile_with_opts(options))
}
}
Expand All @@ -233,8 +235,11 @@ impl Compile for Vec<u8> {
#[inline(always)]
fn compile_with_opts(self, options: Options) -> Result<Box<Module>, Report> {
String::from_utf8(self)
.into_diagnostic()
.wrap_err("parsing failed: expected source code to be valid utf-8")
.map_err(|err| {
let error = crate::parser::ParsingError::from(err.utf8_error());
Report::from(error).with_source_code(err.into_bytes())
})
.wrap_err("parsing failed: invalid source code")
.and_then(|source| source.compile_with_opts(options))
}
}
Expand All @@ -245,7 +250,10 @@ where
{
fn compile_with_opts(self, options: Options) -> Result<Box<Module>, Report> {
let content = String::from_utf8(self.inner().as_ref().to_vec())
.into_diagnostic()
.map_err(|err| {
let error = crate::parser::ParsingError::from(err.utf8_error());
Report::from(error).with_source_code(err.into_bytes())
})
.wrap_err("parsing failed: expected source code to be valid utf-8")?;
Arc::new(SourceFile::new(self.name(), content)).compile_with_opts(options)
}
Expand All @@ -254,7 +262,7 @@ where
#[cfg(feature = "std")]
impl<'a> Compile for &'a std::path::Path {
fn compile_with_opts(self, options: Options) -> Result<Box<Module>, Report> {
use crate::ast::Ident;
use crate::{ast::Ident, library::PathError};
use std::path::Component;

let path = match options.path {
Expand Down
5 changes: 1 addition & 4 deletions assembly/src/library/masl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ mod use_std {
where
P: AsRef<Path>,
{
use vm_core::utils::WriteAdapter;

fs::create_dir_all(&dir_path)?;
let mut path = dir_path.as_ref().join(self.namespace.as_ref());
path.set_extension(Self::LIBRARY_EXTENSION);
Expand All @@ -198,8 +196,7 @@ mod use_std {
// needs to be addressed in winterfall at some point
std::panic::catch_unwind(|| {
let mut file = fs::File::create(path)?;
let mut adapter = WriteAdapter::new(&mut file);
self.write_into(&mut adapter);
self.write_into(&mut file);
Ok(())
})
.map_err(|p| {
Expand Down
26 changes: 26 additions & 0 deletions assembly/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ pub enum ParsingError {
#[error("parsing failed due to unexpected input")]
#[diagnostic()]
Failed = 0,
#[error("expected input to be valid utf8, but invalid byte sequences were found")]
#[diagnostic()]
InvalidUtf8 {
#[label("invalid byte sequence starts here")]
span: SourceSpan,
},
#[error("expected input to be valid utf8, but end-of-file was reached before final codepoint was read")]
#[diagnostic()]
IncompleteUtf8 {
#[label("the codepoint starting here is incomplete")]
span: SourceSpan,
},
#[error("invalid syntax")]
#[diagnostic()]
InvalidToken {
Expand Down Expand Up @@ -252,6 +264,20 @@ impl PartialEq for ParsingError {
}
}

impl From<core::str::Utf8Error> for ParsingError {
fn from(err: core::str::Utf8Error) -> Self {
let start = u32::try_from(err.valid_up_to()).ok().unwrap_or(u32::MAX);
match err.error_len() {
None => Self::IncompleteUtf8 {
span: SourceSpan::at(start),
},
Some(len) => Self::InvalidUtf8 {
span: SourceSpan::new(start..(start + len as u32)),
},
}
}
}

impl<'a> From<ParseError<'a>> for ParsingError {
fn from(err: ParseError) -> Self {
use super::Token;
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/decorators/assembly_op.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::string::*;
use alloc::string::String;
use core::fmt;

// ASSEMBLY OP
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/decorators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::collections::*;
use alloc::vec::Vec;
use core::fmt;

mod advice;
Expand Down
3 changes: 2 additions & 1 deletion core/src/program/blocks/call_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{fmt, hasher, Digest, Felt, Operation};
use super::{hasher, Digest, Felt, Operation};
use core::fmt;

// CALL BLOCK
// ================================================================================================
Expand Down
3 changes: 2 additions & 1 deletion core/src/program/blocks/dyn_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{fmt, Digest, Felt, Operation};
use super::{Digest, Felt, Operation};
use core::fmt;

// CONSTANTS
// ================================================================================================
Expand Down
5 changes: 3 additions & 2 deletions core/src/program/blocks/join_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{fmt, hasher, CodeBlock, Digest, Felt, Operation};
use crate::utils::boxed::*;
use super::{hasher, CodeBlock, Digest, Felt, Operation};
use alloc::boxed::Box;
use core::fmt;

// JOIN BLOCKS
// ================================================================================================
Expand Down
5 changes: 3 additions & 2 deletions core/src/program/blocks/loop_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{fmt, hasher, CodeBlock, Digest, Felt, Operation};
use crate::utils::boxed::*;
use super::{hasher, CodeBlock, Digest, Felt, Operation};
use alloc::boxed::Box;
use core::fmt;

// LOOP BLOCK
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{hasher, Digest, Felt, Operation};
use crate::utils::collections::*;
use crate::DecoratorList;
use alloc::vec::Vec;
use core::fmt;

mod call_block;
Expand Down
Loading

0 comments on commit b0a8361

Please sign in to comment.