Skip to content

Commit 5b3142a

Browse files
committed
trust the compiler to inline stuff for us, inline is a heuristic anyway and doesn't guarantee inlining
1 parent ceb512f commit 5b3142a

File tree

5 files changed

+82
-82
lines changed

5 files changed

+82
-82
lines changed

expr/src/lib.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum Tag {
9494
// - stay shared as long as possible
9595
// - bring shared information to the front (bulk)
9696

97-
#[inline(always)]
97+
#[inline]
9898
pub const fn item_byte(b: Tag) -> u8 {
9999
match b {
100100
Tag::NewVar => { 0b1100_0000 | 0 }
@@ -104,7 +104,7 @@ pub const fn item_byte(b: Tag) -> u8 {
104104
}
105105
}
106106

107-
#[inline(always)]
107+
#[inline]
108108
pub fn byte_item(b: u8) -> Tag {
109109
if b == 0b1100_0000 { return Tag::NewVar; }
110110
else if (b & 0b1100_0000) == 0b1100_0000 { return Tag::SymbolSize(b & 0b0011_1111) }
@@ -197,12 +197,12 @@ macro_rules! traverse {
197197
($t1:ty, $t2:ty, $x:expr, $new_var:expr, $var_ref:expr, $symbol:expr, $zero:expr, $add:expr, $finalize:expr) => {{
198198
struct AnonTraversal {}
199199
impl Traversal<$t1, $t2> for AnonTraversal {
200-
#[inline(always)] fn new_var(&mut self, offset: usize) -> $t2 { ($new_var)(offset) }
201-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> $t2 { ($var_ref)(offset, i) }
202-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> $t2 { ($symbol)(offset, s) }
203-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> $t1 { ($zero)(offset, a) }
204-
#[inline(always)] fn add(&mut self, offset: usize, acc: $t1, sub: $t2) -> $t1 { ($add)(offset, acc, sub) }
205-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: $t1) -> $t2 { ($finalize)(offset, acc) }
200+
#[inline] fn new_var(&mut self, offset: usize) -> $t2 { ($new_var)(offset) }
201+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> $t2 { ($var_ref)(offset, i) }
202+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> $t2 { ($symbol)(offset, s) }
203+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> $t1 { ($zero)(offset, a) }
204+
#[inline] fn add(&mut self, offset: usize, acc: $t1, sub: $t2) -> $t1 { ($add)(offset, acc, sub) }
205+
#[inline] fn finalize(&mut self, offset: usize, acc: $t1) -> $t2 { ($finalize)(offset, acc) }
206206
}
207207

208208
execute_loop(&mut AnonTraversal{}, $x, 0).1
@@ -994,15 +994,15 @@ let mut stack: Vec<(u8, A)> = Vec::with_capacity(8);
994994
struct DebugTraversal { string: String, transient: bool }
995995
#[allow(unused_variables)]
996996
impl Traversal<(), ()> for DebugTraversal {
997-
#[inline(always)] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.string.push(' '); }; self.string.push('$'); }
998-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.string.push(' '); }; self.string.push('_'); self.string.push_str((i as u16 + 1).to_string().as_str()); }
999-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { match std::str::from_utf8(s) {
997+
#[inline] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.string.push(' '); }; self.string.push('$'); }
998+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.string.push(' '); }; self.string.push('_'); self.string.push_str((i as u16 + 1).to_string().as_str()); }
999+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { match std::str::from_utf8(s) {
10001000
Ok(string) => { if self.transient { self.string.push(' '); }; self.string.push_str(string); }
10011001
Err(_) => { if self.transient { self.string.push(' '); }; for b in s { self.string.push_str(format!("\\x{:x}", b).as_str()); }; }
10021002
} }
1003-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.string.push(' '); }; self.string.push('('); self.transient = false; }
1004-
#[inline(always)] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1005-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.string.push(')'); }
1003+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.string.push(' '); }; self.string.push('('); self.transient = false; }
1004+
#[inline] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1005+
#[inline] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.string.push(')'); }
10061006
}
10071007

10081008
impl Debug for Expr {
@@ -1016,59 +1016,59 @@ impl Debug for Expr {
10161016
struct SerializerTraversal<'a, Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str> { out: &'a mut Target, map_symbol: F, transient: bool }
10171017
#[allow(unused_variables, unused_must_use)]
10181018
impl <Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str> Traversal<(), ()> for SerializerTraversal<'_, Target, F> {
1019-
#[inline(always)] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("$".as_bytes()); }
1020-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("_".as_bytes()); self.out.write((i as u16 + 1).to_string().as_bytes()); }
1021-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_symbol)(s).as_bytes()); }
1022-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("(".as_bytes()); self.transient = false; }
1023-
#[inline(always)] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1024-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.out.write(")".as_bytes()); }
1019+
#[inline] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("$".as_bytes()); }
1020+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("_".as_bytes()); self.out.write((i as u16 + 1).to_string().as_bytes()); }
1021+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_symbol)(s).as_bytes()); }
1022+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("(".as_bytes()); self.transient = false; }
1023+
#[inline] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1024+
#[inline] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.out.write(")".as_bytes()); }
10251025
}
10261026

10271027
struct SerializerTraversal2<'a, Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str, G : Fn(u8, bool) -> &'static str> { out: &'a mut Target, map_symbol: F, map_variable: G, transient: bool, n: u8 }
10281028
#[allow(unused_variables, unused_must_use)]
10291029
impl <Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str, G : Fn(u8, bool) -> &'static str> Traversal<(), ()> for SerializerTraversal2<'_, Target, F, G> {
1030-
#[inline(always)] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_variable)(self.n, true).as_bytes()); self.n += 1; }
1031-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_variable)(i, false).as_bytes()); }
1032-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_symbol)(s).as_bytes()); }
1033-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("(".as_bytes()); self.transient = false; }
1034-
#[inline(always)] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1035-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.out.write(")".as_bytes()); }
1030+
#[inline] fn new_var(&mut self, offset: usize) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_variable)(self.n, true).as_bytes()); self.n += 1; }
1031+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_variable)(i, false).as_bytes()); }
1032+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write((self.map_symbol)(s).as_bytes()); }
1033+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> () { if self.transient { self.out.write(" ".as_bytes()); }; self.out.write("(".as_bytes()); self.transient = false; }
1034+
#[inline] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () { self.transient = true; }
1035+
#[inline] fn finalize(&mut self, offset: usize, acc: ()) -> () { self.out.write(")".as_bytes()); }
10361036
}
10371037

10381038
struct SerializerTraversalHighlights<'a, 't, Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str, G : Fn(u8, bool) -> &'static str> { out: &'a mut Target, map_symbol: F, map_variable: G, transient: bool, n: u8, targets: &'t [(usize, &'static str, &'static str)] }
10391039
#[allow(unused_variables, unused_must_use)]
10401040
impl <Target : std::io::Write, F : for <'b> Fn(&'b [u8]) -> &'b str, G : Fn(u8, bool) -> &'static str> Traversal<Option<&'static str>, ()> for SerializerTraversalHighlights<'_, '_, Target, F, G> {
1041-
#[inline(always)] fn new_var(&mut self, offset: usize) -> () {
1041+
#[inline] fn new_var(&mut self, offset: usize) -> () {
10421042
if self.transient { self.out.write(" ".as_bytes()); };
10431043
if offset == self.targets[0].0 { self.out.write(self.targets[0].1.as_bytes()); }
10441044
self.out.write((self.map_variable)(self.n, true).as_bytes());
10451045
if offset == self.targets[0].0 { self.out.write(self.targets[0].2.as_bytes()); self.targets = &self.targets[1..]; }
10461046
self.n += 1;
10471047
}
1048-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> () {
1048+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> () {
10491049
if self.transient { self.out.write(" ".as_bytes()); };
10501050
if offset == self.targets[0].0 { self.out.write(self.targets[0].1.as_bytes()); }
10511051
self.out.write((self.map_variable)(i, false).as_bytes());
10521052
if offset == self.targets[0].0 { self.out.write(self.targets[0].2.as_bytes()); self.targets = &self.targets[1..]; }
10531053
}
1054-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> () {
1054+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> () {
10551055
if self.transient { self.out.write(" ".as_bytes()); };
10561056
if offset == self.targets[0].0 { self.out.write(self.targets[0].1.as_bytes()); }
10571057
self.out.write((self.map_symbol)(s).as_bytes());
10581058
if offset == self.targets[0].0 { self.out.write(self.targets[0].2.as_bytes()); self.targets = &self.targets[1..]; }
10591059
}
1060-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> Option<&'static str> {
1060+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> Option<&'static str> {
10611061
if self.transient { self.out.write(" ".as_bytes()); };
10621062
if offset == self.targets[0].0 { self.out.write(self.targets[0].1.as_bytes()); }
10631063
self.out.write("(".as_bytes()); self.transient = false;
10641064
if offset == self.targets[0].0 { let r = Some(self.targets[0].2); self.targets = &self.targets[1..]; r }
10651065
else { None }
10661066
}
1067-
#[inline(always)] fn add(&mut self, offset: usize, acc: Option<&'static str>, sub: ()) -> Option<&'static str> {
1067+
#[inline] fn add(&mut self, offset: usize, acc: Option<&'static str>, sub: ()) -> Option<&'static str> {
10681068
self.transient = true;
10691069
acc
10701070
}
1071-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: Option<&'static str>) -> () {
1071+
#[inline] fn finalize(&mut self, offset: usize, acc: Option<&'static str>) -> () {
10721072
self.out.write(")".as_bytes());
10731073
if let Some(end) = acc { self.out.write(end.as_bytes()); }
10741074
}
@@ -1122,7 +1122,7 @@ impl ExprZipper {
11221122
}
11231123
}
11241124

1125-
#[inline(always)]
1125+
#[inline]
11261126
pub fn write_symbol(&mut self, value: &[u8]) -> bool {
11271127
unsafe {
11281128
let l = value.len();
@@ -1599,12 +1599,12 @@ impl std::hash::Hash for ExprEnv {
15991599

16001600
pub struct TraverseSide { ee: ExprEnv }
16011601
impl Traversal<(), ()> for TraverseSide {
1602-
#[inline(always)] fn new_var(&mut self, offset: usize) -> () { self.ee.v += 1; }
1603-
#[inline(always)] fn var_ref(&mut self, offset: usize, i: u8) -> () {}
1604-
#[inline(always)] fn symbol(&mut self, offset: usize, s: &[u8]) -> () {}
1605-
#[inline(always)] fn zero(&mut self, offset: usize, a: u8) -> () {}
1606-
#[inline(always)] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () {}
1607-
#[inline(always)] fn finalize(&mut self, offset: usize, acc: ()) -> () {}
1602+
#[inline] fn new_var(&mut self, offset: usize) -> () { self.ee.v += 1; }
1603+
#[inline] fn var_ref(&mut self, offset: usize, i: u8) -> () {}
1604+
#[inline] fn symbol(&mut self, offset: usize, s: &[u8]) -> () {}
1605+
#[inline] fn zero(&mut self, offset: usize, a: u8) -> () {}
1606+
#[inline] fn add(&mut self, offset: usize, acc: (), sub: ()) -> () {}
1607+
#[inline] fn finalize(&mut self, offset: usize, acc: ()) -> () {}
16081608
}
16091609

16101610
impl ExprEnv {

expr/src/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ macro_rules! destruct {
143143

144144
impl TryFrom<Expr> for i32 {
145145
type Error = String;
146-
#[inline(always)]
146+
#[inline]
147147
fn try_from(value: Expr) -> Result<Self, Self::Error> {
148148
let tag = unsafe { byte_item(*value.ptr) };
149149
if tag != Tag::SymbolSize(4) {
@@ -163,36 +163,36 @@ impl SerializableExpr for i32 {
163163
}
164164

165165
impl DeserializableExpr for i32 {
166-
#[inline(always)]
166+
#[inline]
167167
fn advanced(e: Expr) -> usize {
168168
4
169169
}
170-
#[inline(always)]
170+
#[inline]
171171
fn check(e: Expr) -> bool {
172172
unsafe { *e.ptr == item_byte(Tag::SymbolSize(4)) }
173173
}
174-
#[inline(always)]
174+
#[inline]
175175
fn deserialize_unchecked(e: Expr) -> Self {
176176
unsafe { std::ptr::read_unaligned(e.ptr.add(1) as *const i32) }.swap_bytes()
177177
}
178178
}
179179

180180
impl DeserializableExpr for &str {
181-
#[inline(always)]
181+
#[inline]
182182
fn advanced(e: Expr) -> usize {
183183
unsafe {
184184
let Tag::SymbolSize(arity) = byte_item(*e.ptr) else { panic!("wrong symbol for str") };
185185
1usize + (arity as usize)
186186
}
187187
}
188-
#[inline(always)]
188+
#[inline]
189189
fn check(e: Expr) -> bool {
190190
unsafe {
191191
let Tag::SymbolSize(arity) = byte_item(*e.ptr) else { unreachable!() };
192192
str::from_utf8(slice_from_raw_parts(e.ptr.add(1), arity as _).as_ref().unwrap()).is_ok()
193193
}
194194
}
195-
#[inline(always)]
195+
#[inline]
196196
fn deserialize_unchecked(e: Expr) -> Self {
197197
unsafe {
198198
let Tag::SymbolSize(arity) = byte_item(*e.ptr) else { unreachable!() };

frontend/src/bytestring_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl <'a> Context<'a> {
3232
Context{ src: r, loc: 0, variables: vec![] }
3333
}
3434

35-
#[inline(always)]
35+
#[inline]
3636
fn peek(&mut self) -> Result<u8, ParserError> {
3737
if self.loc == self.src.len() {
3838
Err(ParserError::UnexpectedEOF)
@@ -41,7 +41,7 @@ impl <'a> Context<'a> {
4141
}
4242
}
4343

44-
#[inline(always)]
44+
#[inline]
4545
fn next(&mut self) -> Result<u8, ParserError> {
4646
if self.loc == self.src.len() {
4747
Err(ParserError::UnexpectedEOF)
@@ -52,7 +52,7 @@ impl <'a> Context<'a> {
5252
}
5353
}
5454

55-
#[inline(always)]
55+
#[inline]
5656
fn has_next(&mut self) -> bool {
5757
self.loc < self.src.len()
5858
}

frontend/src/json_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl<'a> Parser<'a> {
468468
}
469469

470470
// Check if we are at the end of the source.
471-
#[inline(always)]
471+
#[inline]
472472
fn is_eof(&mut self) -> bool {
473473
self.index == self.length
474474
}
@@ -479,7 +479,7 @@ impl<'a> Parser<'a> {
479479
// very very rarely, lead to a situation where the same byte is read
480480
// twice, but since this operation is using a raw pointer, the cost
481481
// is virtually irrelevant.
482-
#[inline(always)]
482+
#[inline]
483483
fn read_byte(&mut self) -> u8 {
484484
debug_assert!(self.index < self.length, "Reading out of bounds");
485485

@@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
488488

489489
// Manually increment the index. Calling `read_byte` and then `bump`
490490
// is equivalent to consuming a byte on an iterator.
491-
#[inline(always)]
491+
#[inline]
492492
fn bump(&mut self) {
493493
self.index = self.index.wrapping_add(1);
494494
}

0 commit comments

Comments
 (0)