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

limit morphic to trivial analysis to avoid inplace mutation bugs #7370

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
17 changes: 13 additions & 4 deletions crates/compiler/alias_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,16 @@ where

match opt_level {
OptLevel::Development | OptLevel::Normal => morphic_lib::solve_trivial(program),
OptLevel::Optimize | OptLevel::Size => morphic_lib::solve(program),
// TODO(#7367): Change this back to `morphic_lib::solve`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this comment given that it is faster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a lot more detail into the todo. My gut feeling is that we want full morphic in the long run, but the bug is leading to it having worse perf than it should. I would guess that once the bug is fixed, we will be able to find cases with solid perf wins from morphic.

// For now, using solve_trivial to avoid bug with loops.
// Note: when disabling this, there was not much of a change in performance.
// Notably, NQueens was about 5% slower. False interpreter was 0-5% faster (depending on input).
// cFold and derive saw minor gains ~1.5%. rBTreeCk saw a big gain of ~4%.
// This feels wrong, morphic should not really be able to slow down code.
// Likely, noise or the bug and wrong inplace mutation lead to these perf changes.
// When re-enabling this, we should analysis the perf and inplace mutations of a few apps.
// It might be the case that our current benchmarks just aren't affected by morphic much.
OptLevel::Optimize | OptLevel::Size => morphic_lib::solve_trivial(program),
}
}

Expand Down Expand Up @@ -1026,10 +1035,10 @@ fn lowlevel_spec<'a>(
let _unit1 = builder.add_touch(block, cell)?;
let _unit2 = builder.add_update(block, update_mode_var, cell)?;

builder.add_bag_insert(block, bag, to_insert)?;
let new_bag = builder.add_bag_insert(block, bag, to_insert)?;

let old_value = builder.add_bag_get(block, bag)?;
let new_list = with_new_heap_cell(builder, block, bag)?;
let old_value = builder.add_bag_get(block, new_bag)?;
let new_list = with_new_heap_cell(builder, block, new_bag)?;

// depending on the types, the list or value will come first in the struct
let fields = match interner.get_repr(layout) {
Expand Down