use compiler intrinsics' assume
This commit is contained in:
parent
21a586913a
commit
94258b4cb1
@ -10,7 +10,10 @@ use egui::{
|
|||||||
};
|
};
|
||||||
use epaint::Color32;
|
use epaint::Color32;
|
||||||
use parsing::parsing::{process_func_str, BackingFunction};
|
use parsing::parsing::{process_func_str, BackingFunction};
|
||||||
use std::fmt::{self, Debug};
|
use std::{
|
||||||
|
fmt::{self, Debug},
|
||||||
|
intrinsics::assume,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(threading)]
|
#[cfg(threading)]
|
||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
@ -233,6 +236,8 @@ impl FunctionEntry {
|
|||||||
let resolution: f64 = settings.plot_width as f64 / (max_x.abs() + min_x.abs());
|
let resolution: f64 = settings.plot_width as f64 / (max_x.abs() + min_x.abs());
|
||||||
let resolution_iter = resolution_helper(&settings.plot_width + 1, min_x, &resolution);
|
let resolution_iter = resolution_helper(&settings.plot_width + 1, min_x, &resolution);
|
||||||
|
|
||||||
|
unsafe { assume(!resolution_iter.is_empty()) }
|
||||||
|
|
||||||
// Makes sure proper arguments are passed when integral is enabled
|
// Makes sure proper arguments are passed when integral is enabled
|
||||||
if self.integral && settings.integral_changed {
|
if self.integral && settings.integral_changed {
|
||||||
self.invalidate_integral();
|
self.invalidate_integral();
|
||||||
@ -330,6 +335,10 @@ impl FunctionEntry {
|
|||||||
.collect();
|
.collect();
|
||||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||||
self.derivative_data = data;
|
self.derivative_data = data;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
assume(!self.derivative_data.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.nth_derviative && self.nth_derivative_data.is_none() {
|
if self.nth_derviative && self.nth_derivative_data.is_none() {
|
||||||
@ -338,6 +347,10 @@ impl FunctionEntry {
|
|||||||
.collect();
|
.collect();
|
||||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||||
self.nth_derivative_data = Some(data);
|
self.nth_derivative_data = Some(data);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
assume(self.nth_derivative_data.is_some());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,6 +364,9 @@ impl FunctionEntry {
|
|||||||
);
|
);
|
||||||
self.integral_data =
|
self.integral_data =
|
||||||
Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area));
|
Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area));
|
||||||
|
unsafe {
|
||||||
|
assume(self.integral_data.is_some());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.invalidate_integral();
|
self.invalidate_integral();
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use std::intrinsics::assume;
|
||||||
|
|
||||||
use egui::{text::CCursor, text_edit::CursorRange, TextEdit};
|
use egui::{text::CCursor, text_edit::CursorRange, TextEdit};
|
||||||
use epaint::text::cursor::{Cursor, PCursor, RCursor};
|
use epaint::text::cursor::{Cursor, PCursor, RCursor};
|
||||||
use parsing::suggestions::{self, generate_hint, Hint};
|
use parsing::suggestions::{self, generate_hint, Hint};
|
||||||
@ -52,6 +54,12 @@ impl<'a> AutoComplete<'a> {
|
|||||||
|
|
||||||
match self.hint {
|
match self.hint {
|
||||||
Hint::Many(hints) => {
|
Hint::Many(hints) => {
|
||||||
|
// Impossible for plural hints to be singular or non-existant
|
||||||
|
unsafe {
|
||||||
|
assume(hints.len() > 1);
|
||||||
|
assume(!hints.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
match movement {
|
match movement {
|
||||||
Movement::Up => {
|
Movement::Up => {
|
||||||
// subtract one, if fail, set to maximum index value.
|
// subtract one, if fail, set to maximum index value.
|
||||||
@ -65,6 +73,8 @@ impl<'a> AutoComplete<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Movement::Complete => {
|
Movement::Complete => {
|
||||||
|
unsafe { assume(hints.len() >= (self.i + 1)) }
|
||||||
|
|
||||||
self.apply_hint(hints[self.i]);
|
self.apply_hint(hints[self.i]);
|
||||||
}
|
}
|
||||||
Movement::None => {}
|
Movement::None => {}
|
||||||
@ -87,7 +97,7 @@ impl<'a> AutoComplete<'a> {
|
|||||||
|
|
||||||
/// Moves cursor of TextEdit `te_id` to the end
|
/// Moves cursor of TextEdit `te_id` to the end
|
||||||
pub fn move_cursor_to_end(ctx: &egui::Context, te_id: egui::Id) {
|
pub fn move_cursor_to_end(ctx: &egui::Context, te_id: egui::Id) {
|
||||||
let mut state = TextEdit::load_state(ctx, te_id).expect("Expected TextEdit");
|
let mut state = unsafe { TextEdit::load_state(ctx, te_id).unwrap_unchecked() };
|
||||||
state.set_cursor_range(Some(CursorRange::one(Cursor {
|
state.set_cursor_range(Some(CursorRange::one(Cursor {
|
||||||
ccursor: CCursor {
|
ccursor: CCursor {
|
||||||
index: 0,
|
index: 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user