Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for crate keyword. #6284

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions corelib/src/array.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#[feature("deprecated-index-traits")]
use core::traits::IndexView;
use crate::traits::IndexView;

use core::box::BoxTrait;
use crate::box::BoxTrait;
#[allow(unused_imports)]
use core::gas::withdraw_gas;
use crate::gas::withdraw_gas;
#[allow(unused_imports)]
use core::option::OptionTrait;
use core::serde::Serde;
use core::metaprogramming::TypeEqual;
use core::iter::Iterator;
use core::RangeCheck;
use crate::option::OptionTrait;
use crate::serde::Serde;
use crate::metaprogramming::TypeEqual;
use crate::iter::Iterator;
use crate::RangeCheck;

/// A collection of elements of the same type continuous in memory.
#[derive(Drop)]
Expand Down Expand Up @@ -543,7 +543,7 @@ impl SpanIterator<T> of Iterator<SpanIter<T>> {
}
}

impl SpanIntoIterator<T> of core::iter::IntoIterator<Span<T>> {
impl SpanIntoIterator<T> of crate::iter::IntoIterator<Span<T>> {
type IntoIter = SpanIter<T>;
fn into_iter(self: Span<T>) -> SpanIter<T> {
SpanIter { span: self }
Expand All @@ -556,9 +556,9 @@ pub struct ArrayIter<T> {
array: Array<T>,
}

impl ArrayIterClone<T, +core::clone::Clone<T>, +Drop<T>> of core::clone::Clone<ArrayIter<T>> {
impl ArrayIterClone<T, +crate::clone::Clone<T>, +Drop<T>> of crate::clone::Clone<ArrayIter<T>> {
fn clone(self: @ArrayIter<T>) -> ArrayIter<T> {
ArrayIter { array: core::clone::Clone::clone(self.array), }
ArrayIter { array: crate::clone::Clone::clone(self.array), }
}
}

Expand All @@ -569,7 +569,7 @@ impl ArrayIterator<T> of Iterator<ArrayIter<T>> {
}
}

impl ArrayIntoIterator<T> of core::iter::IntoIterator<Array<T>> {
impl ArrayIntoIterator<T> of crate::iter::IntoIterator<Array<T>> {
type IntoIter = ArrayIter<T>;
fn into_iter(self: Array<T>) -> ArrayIter<T> {
ArrayIter { array: self }
Expand Down
6 changes: 3 additions & 3 deletions corelib/src/box.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ pub impl BoxImpl<T> of BoxTrait<T> {
}
}

impl BoxDeref<T> of core::ops::Deref<Box<T>> {
impl BoxDeref<T> of crate::ops::Deref<Box<T>> {
type Target = T;
fn deref(self: Box<T>) -> T {
self.unbox()
}
}

impl BoxDebug<T, impl TDebug: core::fmt::Debug<T>> of core::fmt::Debug<Box<T>> {
fn fmt(self: @Box<T>, ref f: core::fmt::Formatter) -> Result<(), core::fmt::Error> {
impl BoxDebug<T, impl TDebug: crate::fmt::Debug<T>> of crate::fmt::Debug<Box<T>> {
fn fmt(self: @Box<T>, ref f: crate::fmt::Formatter) -> Result<(), crate::fmt::Error> {
write!(f, "&")?;
TDebug::fmt(self.as_snapshot().unbox(), ref f)
}
Expand Down
24 changes: 12 additions & 12 deletions corelib/src/byte_array.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use core::array::{ArrayTrait, SpanTrait};
use crate::array::{ArrayTrait, SpanTrait};
#[allow(unused_imports)]
use core::bytes_31::{
use crate::bytes_31::{
BYTES_IN_BYTES31, Bytes31Trait, one_shift_left_bytes_felt252, one_shift_left_bytes_u128,
POW_2_128, POW_2_8, U128IntoBytes31, U8IntoBytes31
};
use core::clone::Clone;
use core::cmp::min;
use crate::clone::Clone;
use crate::cmp::min;
#[allow(unused_imports)]
use core::integer::{u128_safe_divmod, U32TryIntoNonZero};
use core::option::OptionTrait;
use core::traits::{Into, TryInto};
use crate::integer::{u128_safe_divmod, U32TryIntoNonZero};
use crate::option::OptionTrait;
use crate::traits::{Into, TryInto};
#[allow(unused_imports)]
use core::serde::Serde;
use crate::serde::Serde;
#[allow(unused_imports)]
use core::zeroable::NonZeroIntoImpl;
use crate::zeroable::NonZeroIntoImpl;

/// A magic constant for identifying serialization of ByteArrays. An array of felt252s with this
/// magic as one of the felt252s indicates that right after it you should expect a serialized
Expand All @@ -38,7 +38,7 @@ pub struct ByteArray {
pub(crate) pending_word_len: usize,
}

pub(crate) impl ByteArrayStringLiteral of core::string::StringLiteral<ByteArray>;
pub(crate) impl ByteArrayStringLiteral of crate::string::StringLiteral<ByteArray>;

#[generate_trait]
pub impl ByteArrayImpl of ByteArrayTrait {
Expand Down Expand Up @@ -353,15 +353,15 @@ impl ByteArrayAdd of Add<ByteArray> {
}
}
#[feature("deprecated-op-assign-traits")]
impl ByteArrayAddEq of core::traits::AddEq<ByteArray> {
impl ByteArrayAddEq of crate::traits::AddEq<ByteArray> {
#[inline]
fn add_eq(ref self: ByteArray, other: ByteArray) {
self.append(@other);
}
}

#[feature("deprecated-index-traits")]
pub(crate) impl ByteArrayIndexView of core::traits::IndexView<ByteArray, usize, u8> {
pub(crate) impl ByteArrayIndexView of crate::traits::IndexView<ByteArray, usize, u8> {
fn index(self: @ByteArray, index: usize) -> u8 {
self.at(index).expect('Index out of bounds')
}
Expand Down
26 changes: 13 additions & 13 deletions corelib/src/bytes_31.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::traits::{Into, TryInto};
use core::option::OptionTrait;
use crate::traits::{Into, TryInto};
use crate::option::OptionTrait;
#[allow(unused_imports)]
use core::integer::{u128_safe_divmod, u128_to_felt252};
use core::RangeCheck;
use crate::integer::{u128_safe_divmod, u128_to_felt252};
use crate::RangeCheck;

pub(crate) const BYTES_IN_BYTES31: usize = 31;
const BYTES_IN_U128: usize = 16;
Expand Down Expand Up @@ -32,13 +32,13 @@ pub impl Bytes31Impl of Bytes31Trait {
}

#[feature("deprecated-index-traits")]
pub(crate) impl Bytes31IndexView of core::traits::IndexView<bytes31, usize, u8> {
pub(crate) impl Bytes31IndexView of crate::traits::IndexView<bytes31, usize, u8> {
fn index(self: @bytes31, index: usize) -> u8 {
self.at(index)
}
}

impl Bytes31BitSize of core::num::traits::BitSize<bytes31> {
impl Bytes31BitSize of crate::num::traits::BitSize<bytes31> {
fn bits() -> usize {
248
}
Expand All @@ -63,31 +63,31 @@ pub(crate) impl Felt252TryIntoBytes31 of TryInto<felt252, bytes31> {
}
}

impl Bytes31Serde = core::serde::into_felt252_based::SerdeImpl<bytes31>;
impl Bytes31Serde = crate::serde::into_felt252_based::SerdeImpl<bytes31>;

pub(crate) impl U8IntoBytes31 of Into<u8, bytes31> {
fn into(self: u8) -> bytes31 {
core::integer::upcast(self)
crate::integer::upcast(self)
}
}
impl U16IntoBytes31 of Into<u16, bytes31> {
fn into(self: u16) -> bytes31 {
core::integer::upcast(self)
crate::integer::upcast(self)
}
}
impl U32IntoBytes31 of Into<u32, bytes31> {
fn into(self: u32) -> bytes31 {
core::integer::upcast(self)
crate::integer::upcast(self)
}
}
impl U64IntoBytes31 of Into<u64, bytes31> {
fn into(self: u64) -> bytes31 {
core::integer::upcast(self)
crate::integer::upcast(self)
}
}
pub(crate) impl U128IntoBytes31 of Into<u128, bytes31> {
fn into(self: u128) -> bytes31 {
core::integer::upcast(self)
crate::integer::upcast(self)
}
}

Expand Down Expand Up @@ -173,7 +173,7 @@ pub(crate) fn one_shift_left_bytes_u128(n_bytes: usize) -> u128 {
13 => 0x100000000000000000000000000,
14 => 0x10000000000000000000000000000,
15 => 0x1000000000000000000000000000000,
_ => core::panic_with_felt252('n_bytes too big'),
_ => crate::panic_with_felt252('n_bytes too big'),
}
}

Expand Down
26 changes: 14 additions & 12 deletions corelib/src/circuit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct u384 {
pub limb3: u96,
}

pub type u96 = core::internal::bounded_int::BoundedInt<0, 79228162514264337593543950335>;
pub type u96 = crate::internal::bounded_int::BoundedInt<0, 79228162514264337593543950335>;
pub extern type RangeCheck96;
pub extern type AddMod;
pub extern type MulMod;
Expand Down Expand Up @@ -73,8 +73,8 @@ impl DestructU96Guarantee of Destruct<U96Guarantee> {
extern type U96Guarantee;

/// Expose the const required by the libfunc to allow the compiler const reusage.
pub type ConstZero = core::internal::bounded_int::BoundedInt<0, 0>;
pub type ConstOne = core::internal::bounded_int::BoundedInt<1, 1>;
pub type ConstZero = crate::internal::bounded_int::BoundedInt<0, 0>;
pub type ConstOne = crate::internal::bounded_int::BoundedInt<1, 1>;

/// A type that creates a circuit from a tuple of outputs.
pub extern type Circuit<Outputs>;
Expand Down Expand Up @@ -129,7 +129,7 @@ pub enum AddInputResult<C> {
}

mod internal {
use core::traits::PanicDestructForDestruct;
use crate::traits::PanicDestructForDestruct;
impl AddInputResultDrop<C> of Drop<super::AddInputResult<C>>;
impl CircuitDataDrop<C> of Drop<super::CircuitData<C>>;
impl CircuitInputAccumulatorDrop<C> of Drop<super::CircuitInputAccumulator<C>>;
Expand Down Expand Up @@ -195,7 +195,7 @@ trait CircuitDefinition<CES> {
type CircuitType;
}
impl CircuitDefinitionImpl<
T, impl Unwrap: UnwrapCircuitElement<T>, +core::metaprogramming::IsTuple<T>
T, impl Unwrap: UnwrapCircuitElement<T>, +crate::metaprogramming::IsTuple<T>
> of CircuitDefinition<T> {
type CircuitType = Circuit<Unwrap::Unwrapped>;
}
Expand All @@ -218,10 +218,12 @@ impl UnwrapCircuitElementBase<
/// Implementation for unwrapping a tuple of `CircuitElement`s.
impl UnwrapCircuitElementNext<
T,
impl TS: core::metaprogramming::TupleSplit<T>,
impl TS: crate::metaprogramming::TupleSplit<T>,
impl UnwrapHead: UnwrapCircuitElement<TS::Head>,
impl UnwrapRest: UnwrapCircuitElement<TS::Rest>,
impl TEF: core::metaprogramming::TupleExtendFront<UnwrapRest::Unwrapped, UnwrapHead::Unwrapped>,
impl TEF: crate::metaprogramming::TupleExtendFront<
UnwrapRest::Unwrapped, UnwrapHead::Unwrapped
>,
> of UnwrapCircuitElement<T> {
type Unwrapped = TEF::Result;
}
Expand Down Expand Up @@ -310,14 +312,14 @@ impl U384IntoCircuitInputValue of IntoCircuitInputValue<u384> {
pub impl EvalCircuitImpl<C> of EvalCircuitTrait<C> {
// Inlining to make sure possibly huge `C` won't be in a user function name.
#[inline(always)]
fn eval(self: CircuitData<C>, modulus: CircuitModulus) -> core::circuit::EvalCircuitResult<C> {
fn eval(self: CircuitData<C>, modulus: CircuitModulus) -> crate::circuit::EvalCircuitResult<C> {
self.eval_ex(get_circuit_descriptor::<C>(), modulus)
}
// Inlining to make sure possibly huge `C` won't be in a user function name.
#[inline(always)]
fn eval_ex(
self: CircuitData<C>, descriptor: CircuitDescriptor<C>, modulus: CircuitModulus
) -> core::circuit::EvalCircuitResult<C> {
) -> crate::circuit::EvalCircuitResult<C> {
eval_circuit::<C>(descriptor, self, modulus, 0, 1)
}
}
Expand Down Expand Up @@ -426,7 +428,7 @@ extern fn get_circuit_output<C, Output>(

/// Helper module to convert into `u384`.
mod conversions {
use core::internal::{
use crate::internal::{
bounded_int, bounded_int::{BoundedInt, AddHelper, MulHelper, DivRemHelper}
};

Expand Down Expand Up @@ -460,14 +462,14 @@ mod conversions {

pub fn from_u128(value: u128) -> super::u384 {
let (limb1, limb0) = bounded_int::div_rem(value, NZ_POW96_TYPED);
core::circuit::u384 { limb0, limb1: core::integer::upcast(limb1), limb2: 0, limb3: 0 }
crate::circuit::u384 { limb0, limb1: crate::integer::upcast(limb1), limb2: 0, limb3: 0 }
}

pub fn from_u256(value: u256) -> super::u384 {
let (limb1_low32, limb0) = bounded_int::div_rem(value.low, NZ_POW96_TYPED);
let (limb2, limb1_high64) = bounded_int::div_rem(value.high, NZ_POW64_TYPED);
let limb1 = bounded_int::add(bounded_int::mul(limb1_high64, POW32_TYPED), limb1_low32);
core::circuit::u384 { limb0, limb1, limb2: core::integer::upcast(limb2), limb3: 0 }
crate::circuit::u384 { limb0, limb1, limb2: crate::integer::upcast(limb2), limb3: 0 }
}
}

Expand Down
10 changes: 5 additions & 5 deletions corelib/src/clone.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl TCopyClone<T, +Copy<T>> of Clone<T> {
/// Tuple `Clone` implementation.
impl TupleClone<
T,
impl TSF: core::metaprogramming::TupleSnapForward<T>,
impl TSF: crate::metaprogramming::TupleSnapForward<T>,
impl CH: CloneHelper<TSF::SnapForward, T>,
-Copy<T>,
> of Clone<T> {
Expand Down Expand Up @@ -53,12 +53,12 @@ impl FixedSizedArrayCloneHelper<T> of CloneHelper<[@T; 0], [T; 0]> {
/// Recursive implementation of `CloneHelper` for tuple style structs.
impl TupleNextCloneHelper<
T,
impl TH: core::metaprogramming::TupleSplit<T>,
impl HeadNoSnap: core::metaprogramming::SnapRemove<TH::Head>,
impl RestNoSnap: core::metaprogramming::SnapRemove<TH::Rest>,
impl TH: crate::metaprogramming::TupleSplit<T>,
impl HeadNoSnap: crate::metaprogramming::SnapRemove<TH::Head>,
impl RestNoSnap: crate::metaprogramming::SnapRemove<TH::Rest>,
impl HeadHelper: CloneHelper<TH::Head, HeadNoSnap::Result>,
impl RestHelper: CloneHelper<TH::Rest, RestNoSnap::Result>,
impl TEF: core::metaprogramming::TupleExtendFront<RestNoSnap::Result, HeadNoSnap::Result>,
impl TEF: crate::metaprogramming::TupleExtendFront<RestNoSnap::Result, HeadNoSnap::Result>,
+Destruct<HeadNoSnap::Result>,
+Drop<TH::Rest>,
> of CloneHelper<T, TEF::Result> {
Expand Down
10 changes: 5 additions & 5 deletions corelib/src/debug.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[allow(unused_imports)]
use core::array::ArrayTrait;
use core::traits::Into;
use crate::array::ArrayTrait;
use crate::traits::Into;
#[allow(unused_imports)]
use core::option::Option;
use crate::option::Option;

/// Usage:
/// ```
/// use core::debug::PrintTrait;
/// use crate::debug::PrintTrait;
///
/// 1.print();
///
Expand Down Expand Up @@ -127,7 +127,7 @@ pub(crate) impl ArrayGenericPrintImpl of PrintTrait<Array<felt252>> {

/// Prints a byte array as a string.
pub fn print_byte_array_as_string(self: @ByteArray) {
let mut serialized = array![core::byte_array::BYTE_ARRAY_MAGIC];
let mut serialized = array![crate::byte_array::BYTE_ARRAY_MAGIC];
self.serialize(ref serialized);
print(serialized)
}
Expand Down
6 changes: 3 additions & 3 deletions corelib/src/dict.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[feature("deprecated-index-traits")]
use core::traits::{Index, Default, Felt252DictValue};
use crate::traits::{Index, Default, Felt252DictValue};

pub extern type Felt252Dict<T>;
pub extern type SquashedFelt252Dict<T>;
pub extern type Felt252DictEntry<T>;
impl SquashedFelt252DictDrop<T, +Drop<T>> of Drop<SquashedFelt252Dict<T>>;
use core::{RangeCheck, SegmentArena};
use core::gas::GasBuiltin;
use crate::{RangeCheck, SegmentArena};
use crate::gas::GasBuiltin;

pub(crate) extern fn felt252_dict_new<T>() -> Felt252Dict<T> implicits(SegmentArena) nopanic;

Expand Down
Loading