Skip to content

Commit

Permalink
Nightly update. (#6359)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Sep 8, 2024
1 parent d248e2b commit 987d08d
Show file tree
Hide file tree
Showing 48 changed files with 94 additions and 42 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-08-22
toolchain: nightly-2024-09-04
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- run: |
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
components: rustfmt
toolchain: nightly-2024-08-22
toolchain: nightly-2024-09-04
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install nextest
Expand All @@ -86,7 +86,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
components: rustfmt
toolchain: nightly-2024-08-22
toolchain: nightly-2024-09-04
- uses: Swatinem/rust-cache@v2
- run: scripts/rust_fmt.sh --check

Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
components: clippy
toolchain: nightly-2024-08-22
toolchain: nightly-2024-09-04
- uses: Swatinem/rust-cache@v2
- run: >
scripts/clippy.sh
Expand All @@ -142,7 +142,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-08-22
toolchain: nightly-2024-09-04
- uses: Swatinem/rust-cache@v2
- run: >
scripts/docs.sh
Expand Down
8 changes: 5 additions & 3 deletions crates/cairo-lang-casm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ pub struct CasmBuildResult<const BRANCH_COUNT: usize> {
pub branches: [(State, Vec<usize>); BRANCH_COUNT],
}

/// Builder to more easily write casm code without specifically thinking about ap changes and the
/// sizes of opcodes. Wrong usages of it would panic instead of returning a result, as this builder
/// assumes we are in a post validation of parameters stage.
/// Builder to more easily write casm code.
///
/// Allows CASM building without specifically thinking about ap changes and the sizes of opcodes.
/// Wrong usages of it would panic instead of returning a result, as this builder assumes we are in
/// a post validation of parameters stage.
pub struct CasmBuilder {
/// The state at a point of jumping into a label, per label.
label_state: UnorderedHashMap<String, State>,
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-defs/src/plugin_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn escape_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> String {
}

/// Macro to extract unnamed arguments of an inline macro.
///
/// Gets the expected number of unnamed arguments, and the pattern for the allowed bracket types,
/// and returns a fixed size array with the argument expressions.
///
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl<T> ToMaybe<T> for Option<T> {
}

/// Temporary trait to allow conversions from `Maybe<T>` to `Option<T>`.
///
/// The behavior is identical to [Result::ok]. It is used to mark all the location where there
/// is a conversion between the two mechanisms.
// TODO(lior): Remove this trait after converting all the functions.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-filesystem/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct CrateSettings {
}

/// The Cairo edition of a crate.
///
/// Editions are a mechanism to allow breaking changes in the compiler.
/// Compiler minor version updates will always support all editions supported by the previous
/// updates with the same major version. Compiler major version updates may remove support for older
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-filesystem/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl CrateId {
}

/// A trait for getting the internal salsa::InternId of a short id object.
///
/// This id is unstable across runs and should not be used to anything that is externally visible.
/// This is currently used to pick representative for strongly connected components.
pub trait UnstableSalsaId {
Expand Down
4 changes: 3 additions & 1 deletion crates/cairo-lang-lowering/src/destructs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! This module implements the destructor call addition. It is assumed to run after the panic phase.
//! This module implements the destructor call addition.
//!
//! It is assumed to run after the panic phase.
//! This is similar to the borrow checking algorithm, except we handle "undroppable drops" by adding
//! destructor calls.

Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/lower/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl<'db> Index<VariableId> for VariableAllocator<'db> {
}

/// Lowering context for the encapsulating semantic function.
///
/// Each semantic function may generate multiple lowered functions. This context is common to all
/// the generated lowered functions of an encapsulating semantic function.
pub struct EncapsulatingLoweringContext<'db> {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Intermediate representation objects after lowering from semantic.
//!
//! This representation is SSA (static single-assignment): each variable is defined before usage and
//! assigned once. It is also normal form: each function argument is a variable, rather than a
//! compound expression.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/optimizations/remappings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Remove unnecessary remapping of variables optimization.
//!
//! At each convergence, we have one or more branches with remappings of variables.
//! A destination variable `dest` introduced by the remappings must be remapped at every branch
//! `b_i` by mapping a source variable `src_i->dest`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ pub struct ReturnInfo {
}

/// A wrapper around `ReturnInfo` that makes it optional.
///
/// None indicates that the return info is unknown.
/// If early_return_possible() returns true, the function can return early as the return value is
/// already known.
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-lowering/src/optimizations/split_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::{
StatementStructDestructure, VarRemapping, VarUsage, Variable, VariableId,
};

/// Splits all the variables that were created by struct_construct and
/// reintroduces the struct_construct statement when needed.
/// Splits all the variables that were created by struct_construct and reintroduces the
/// struct_construct statement when needed.
///
/// Note that if a member is used after the struct then is means that that struct is copyable.

pub fn split_structs(lowered: &mut FlatLowered) {
if lowered.blocks.is_empty() {
return;
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-plugins/src/plugins/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use cairo_lang_syntax::node::{ast, Terminal, TypedSyntaxNode};
use cairo_lang_utils::try_extract_matches;

/// Plugin that enables ignoring modules not involved in the current config.
///
/// Mostly useful for marking test modules to prevent usage of their functionality out of tests,
/// and reduce compilation time when the tests data isn't required.
#[derive(Debug, Default)]
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-runner/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ fn is_cairo_trace(

/// Converts a sierra statement index to the index of the function that contains it (the index in
/// the list in the sierra program).
///
/// Assumes that the given `statement_idx` is valid (that is within range of the given
/// `sierra_program`) and that the given `sierra_program` is valid, specifically that the first
/// function's entry point is 0.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-semantic/src/expr/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::db::SemanticGroup;
use crate::{semantic, ConcreteStructId, ExprLiteral, ExprStringLiteral, LocalVariable, PatternId};

/// Semantic representation of a Pattern.
///
/// A pattern is a way to "destructure" values. A pattern may introduce new variables that are bound
/// to inner values of a specific value. For example, a tuple pattern destructures a tuple
/// and may result in new variables for an elements of that tuple.
Expand Down
8 changes: 5 additions & 3 deletions crates/cairo-lang-semantic/src/items/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ impl DebugWithDb<dyn SemanticGroup> for GenericArgumentId {
}
}

/// Head of a generic argument. A non-param non-variable generic argument has a head, which
/// represents the kind of the root node in its tree. This is used for caching queries for fast
/// lookups when the generic argument is not completely inferred yet.
/// Head of a generic argument.
///
/// A non-param non-variable generic argument has a head, which represents the kind of the root node
/// in its tree. This is used for caching queries for fast lookups when the generic argument is not
/// completely inferred yet.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum GenericArgumentHead {
Type(TypeHead),
Expand Down
8 changes: 5 additions & 3 deletions crates/cairo-lang-semantic/src/items/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ impl UnstableSalsaId for ImplId {
}
}

/// Head of an impl. A non-param non-variable impl has a head, which represents the kind of the root
/// node in its tree representation. This is used for caching queries for fast lookups when the impl
/// is not completely inferred yet.
/// Head of an impl.
///
/// A non-param non-variable impl has a head, which represents the kind of the root node in its tree
/// representation. This is used for caching queries for fast lookups when the impl is not
/// completely inferred yet.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum ImplHead {
Concrete(ImplDefId),
Expand Down
8 changes: 5 additions & 3 deletions crates/cairo-lang-semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ impl DebugWithDb<dyn SemanticGroup> for TypeLongId {
}
}

/// Head of a type. A type that is not one of {generic param, type variable, impl type} has a head,
/// which represents the kind of the root node in its type tree. This is used for caching queries
/// for fast lookups when the type is not completely inferred yet.
/// Head of a type.
///
/// A type that is not one of {generic param, type variable, impl type} has a head, which represents
/// the kind of the root node in its type tree. This is used for caching queries for fast lookups
/// when the type is not completely inferred yet.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum TypeHead {
Concrete(GenericTypeId),
Expand Down
8 changes: 5 additions & 3 deletions crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ use crate::objects::{
};
use crate::starknet_libfunc_cost_base::starknet_libfunc_cost_base;

/// The cost per each unique key in the dictionary. This cost is pre-charged for each access
/// (read/write/entry), and the overhead cost is refunded for each repeated access.
/// Repeated access is access to a key that has already been accessed before.
/// The cost per each unique key in the dictionary.
///
/// This cost is pre-charged for each access (read/write/entry), and the overhead cost is refunded
/// for each repeated access. Repeated access is access to a key that has already been accessed
/// before.
pub const DICT_SQUASH_UNIQUE_KEY_COST: ConstCost =
ConstCost { steps: 46, holes: 0, range_checks: 6, range_checks96: 0 };
/// The cost per each access to a key after the first access.
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-sierra-generator/src/local_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ struct BranchInfo {

impl<'a> FindLocalsContext<'a> {
/// Given a variable that might be an alias follow aliases until we get the original variable.
pub fn peel_aliases(&'a self, mut var: &'a VariableId) -> &VariableId {
pub fn peel_aliases(&'a self, mut var: &'a VariableId) -> &'a VariableId {
while let Some(alias) = self.aliases.get(var) {
var = alias;
}
var
}
/// Given a variable, that might be an alias of a const, follow the const aliases until we get
/// the root variable.
pub fn peel_const_aliases(&'a self, mut var: &'a VariableId) -> &VariableId {
pub fn peel_const_aliases(&'a self, mut var: &'a VariableId) -> &'a VariableId {
while let Some(alias) = self.const_aliases.get(var) {
var = alias;
}
Expand Down
2 changes: 2 additions & 0 deletions crates/cairo-lang-sierra-generator/src/replace_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub trait SierraIdReplacer {

/// Replaces `cairo_lang_sierra::ids::{ConcreteLibfuncId, ConcreteTypeId, FunctionId}` with a dummy
/// ids whose debug string is the string representing the expanded information about the id.
///
/// For Libfuncs and Types - that would be recursively opening their generic arguments, for
/// functions - that would be getting their original name. For example, while the original debug
/// string may be `[6]`, the resulting debug string may be:
Expand Down Expand Up @@ -194,6 +195,7 @@ pub fn replace_sierra_ids(

/// Replaces `cairo_lang_sierra::ids::{ConcreteLibfuncId, ConcreteTypeId, FunctionId}` with a dummy
/// ids whose debug string is the string representing the expanded information about the id.
///
/// For Libfuncs and Types - that would be recursively opening their generic arguments, for
/// functions - that would be getting their original name. For example, while the original debug
/// string may be `[6]`, the resulting debug string may be:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub struct SourceCodeSpan {
}

/// The mapping between sierra statement indexes and locations in cairo code
/// (if obtainable) which caused the statement to be generated. Should be created using
/// (if obtainable) which caused the statement to be generated.
///
/// Should be created using
/// [`crate::statements_locations::StatementsLocations::extract_statements_source_code_locations`].
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct StatementsSourceCodeLocations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use serde::{Deserialize, Serialize};

/// The mapping from sierra statement index to fully qualified Cairo path of the Cairo function
/// (if obtainable) which caused the statement to be generated. Should be created using
/// (if obtainable) which caused the statement to be generated.
///
/// Should be created using
/// [`crate::statements_locations::StatementsLocations::extract_statements_functions`].
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct StatementsFunctions {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-sierra-generator/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ pub fn dummy_push_values_ex(
}

/// Creates a test for a given function that reads test files.
///
/// filenames - a vector of tests files the test will apply to.
/// db - the salsa DB to use for the test.
/// func - the function to be applied on the test params to generate the tested result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum TopologicalOrderStatus {
}

/// Returns the topological ordering.
///
/// `detect_cycles` - if true, the function will return an error if a cycle is detected, else will
/// not detect the cycle, and ordering within cycles won't be topological.
/// `roots` - the roots of the graph.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-sierra/src/extensions/lib_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ impl From<ConcreteTypeId> for ParamSignature {
}

/// Information regarding the reference created as an output of a library function.
///
/// For example, whether the reference is equal to one of the parameters (as in the dup() function),
/// or whether it's newly allocated local variable.
#[derive(Debug, Clone)]
Expand Down
10 changes: 6 additions & 4 deletions crates/cairo-lang-sierra/src/extensions/modules/coupon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::program::GenericArg;

/// Coupon type `Coupon<function>` (`function::Coupon`) which represents that the cost of a
/// function was paid, without calling the function yet.
///
/// Using the coupon the function can be called without paying the cost.
#[derive(Default)]
pub struct CouponType {}
Expand Down Expand Up @@ -68,10 +69,11 @@ define_libfunc_hierarchy! {
}, CouponConcreteLibfunc
}

/// Libfunc for buying a coupon for a function. The cost of the coupon is the cost of running the
/// function (not including the `call` and `ret` instructions).
/// The coupon can be used to pay in advance for running the function, and run it later for
/// free (paying only for the `call` and `ret` instructions) using `coupon_call`.
/// Libfunc for buying a coupon for a function.
///
/// The cost of the coupon is the cost of running the function (not including the `call` and `ret`
/// instructions). The coupon can be used to pay in advance for running the function, and run it
/// later for free (paying only for the `call` and `ret` instructions) using `coupon_call`.
#[derive(Default)]
pub struct CouponBuyLibfunc {}
impl NamedLibfunc for CouponBuyLibfunc {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-sierra/src/extensions/modules/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl NoGenericArgsGenericLibfunc for EcCreatePointLibfunc {
}

/// Libfunc for creating an EC point from its x coordinate.
///
/// If there exists `y` such that `(x, y)` is on the curve, either `(x, y)` or `(x, -y)` (both
/// constitute valid points on the curve) is returned.
/// Otherwise, nothing is returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::ids::{ConcreteTypeId, GenericTypeId};
use crate::program::{ConcreteTypeLongId, GenericArg};

/// Type representing a dictionary from a felt252 to types of size one.
///
/// This is currently only bounded for all numeric types, Nullable, and Enum types with 2 or less
/// variants, as this are the types that has proper default as 0, and therefore can be properly used
/// as a value in the dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::extensions::NoGenericArgsGenericType;
use crate::ids::GenericTypeId;

/// Type for the Segment Arena builtin.
///
/// This type should be initialized and destructed by the OS.
/// It is assumed to be a pointer to a segment containing the following struct:
/// A data segment start.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-starknet-classes/src/compiler_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn current_compiler_version_id() -> VersionId {
}

/// The version of the Sierra compiler that compiled the contract.
///
/// Major version should be updated in any non-backwards compatible change of the Sierra compiler.
/// Minor version should be updated in any backwards compatible change of the Sierra compiler.
/// For more information see docs/CONTRIBUTING.md.
Expand Down
3 changes: 2 additions & 1 deletion crates/cairo-lang-syntax-codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn reformat_rust_code(text: String) -> String {
}
pub fn reformat_rust_code_inner(text: String) -> String {
let sh = Shell::new().unwrap();
sh.set_var("RUSTUP_TOOLCHAIN", "nightly-2024-08-22");
sh.set_var("RUSTUP_TOOLCHAIN", "nightly-2024-09-04");
let rustfmt_toml = project_root().join("rustfmt.toml");
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml}").stdin(text).read().unwrap();
if !stdout.ends_with('\n') {
Expand Down Expand Up @@ -172,6 +172,7 @@ fn generate_key_fields_code() -> rust::Tokens {
use super::kind::SyntaxKind;

$("/// Gets the vector of children ids that are the indexing key for this SyntaxKind.\n")
$("///\n")
$("/// Each SyntaxKind has some children that are defined in the spec to be its indexing key\n")
$("/// for its stable pointer. See [super::stable_ptr].\n")
pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec<GreenId> {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-syntax/src/attribute/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub const FEATURE_ATTR: &str = "feature";
pub const IMPLICIT_PRECEDENCE_ATTR: &str = "implicit_precedence";

/// An attribute for the declaration of a starknet interface.
///
/// It is used in the starknet crate, however it is defined here because it is currently used in the
/// corelib.
/// TODO(Gil): Remove this once `starknet` is removed from corelib.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-syntax/src/node/key_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use super::ids::GreenId;
use super::kind::SyntaxKind;
/// Gets the vector of children ids that are the indexing key for this SyntaxKind.
///
/// Each SyntaxKind has some children that are defined in the spec to be its indexing key
/// for its stable pointer. See [super::stable_ptr].
pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec<GreenId> {
Expand Down
Loading

0 comments on commit 987d08d

Please sign in to comment.