Skip to content

Commit

Permalink
Removed faulty diagnostic on inlining over generated functions. (#6257)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Aug 22, 2024
1 parent 7590bbc commit 4cf5fa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 9 additions & 6 deletions crates/cairo-lang-lowering/src/inline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use crate::db::LoweringGroup;
use crate::diagnostic::{
LoweringDiagnostic, LoweringDiagnosticKind, LoweringDiagnostics, LoweringDiagnosticsBuilder,
};
use crate::ids::{ConcreteFunctionWithBodyId, FunctionWithBodyId, LocationId};
use crate::ids::{
ConcreteFunctionWithBodyId, FunctionWithBodyId, FunctionWithBodyLongId, LocationId,
};
use crate::lower::context::{VarRequest, VariableAllocator};
use crate::utils::{InliningStrategy, Rebuilder, RebuilderEx};
use crate::{
Expand All @@ -33,15 +35,16 @@ pub fn get_inline_diagnostics(
db: &dyn LoweringGroup,
function_id: FunctionWithBodyId,
) -> Maybe<Diagnostics<LoweringDiagnostic>> {
let semantic_function_id = function_id.base_semantic_function(db);
let inline_config = match function_id.lookup_intern(db) {
FunctionWithBodyLongId::Semantic(id) => db.function_declaration_inline_config(id)?,
FunctionWithBodyLongId::Generated { .. } => InlineConfiguration::None,
};
let mut diagnostics = LoweringDiagnostics::default();

if let InlineConfiguration::Always(_) =
db.function_declaration_inline_config(semantic_function_id)?
{
if let InlineConfiguration::Always(_) = inline_config {
if db.in_cycle(function_id, crate::DependencyType::Call)? {
diagnostics.report(
semantic_function_id.untyped_stable_ptr(db.upcast()),
function_id.base_semantic_function(db).untyped_stable_ptr(db.upcast()),
LoweringDiagnosticKind::CannotInlineFunctionThatMightCallItself,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,11 @@ fn not_cycle() {
#[inline(always)]
fn cycle_if_some(x: Option<felt252>) {
match x {
Option::Some(x) => { cycle(x); },
Option::Some(x) => while x != 0 {},
Option::None => {},
}
}

fn cycle(x: felt252) -> felt252 {
cycle(x)
}

//! > result
not_cycle: ap_change=Ok(Unknown), has_cycles=Ok(true)
cycle_if_some: ap_change=Ok(Unknown), has_cycles=Ok(true)
cycle: ap_change=Ok(Unknown), has_cycles=Ok(true)

0 comments on commit 4cf5fa3

Please sign in to comment.