Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 503dce3

Browse files
committed
Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation Part of #99012 This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair. --- This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example: > code: > ```rust > fn main() { > println!("Hello, world!"); > } > ``` > > before: > ```asm > main: > sub rsp, 56 > lea rax, [rip + .Lanon_hello_world] > mov qword ptr [rsp + 8], rax > mov qword ptr [rsp + 16], 1 > mov qword ptr [rsp + 24], 8 > xorps xmm0, xmm0 > movups xmmword ptr [rsp + 32], xmm0 > lea rdi, [rsp + 8] > call qword ptr [rip + std::io::stdio::_print] > add rsp, 56 > ret > ``` > > after: > ```asm > main: > lea rsi, [rip + .Lanon_hello_world] > mov edi, 29 > jmp qword ptr [rip + std::io::stdio::_print] > ``` (`panic!("Hello, world!");` shows a similar change.) --- This implementation stores all static information as just a single (byte) string, without any indirection: > code: > ```rust > format_args!("Hello, {name:-^20}!") > ``` > > lowering before: > ```rust > fmt::Arguments::new_v1_formatted( > &["Hello, ", "!\n"], > &args, > &[ > Placeholder { > position: 0usize, > flags: 3355443245u32, > precision: format_count::Implied, > width: format_count::Is(20u16), > }, > ], > ) > ``` > > lowering after: > ```rust > fmt::Arguments::new( > b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00", > &args, > ) > ``` This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.) --- The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2 parents 0186755 + cfbdc2c commit 503dce3

58 files changed

Lines changed: 886 additions & 989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
16+
use rustc_span::{ByteSymbol,DUMMY_SP,DesugaringKind,Ident,Span,Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span,call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18361836
let kind = self.make_lowered_await(head_span, iter,FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr{hir_id:self.next_id(), kind,span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span,iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fnexpr_uint(&mutself,sp:Span,ty: ast::UintTy,value:u128) -> hir::Expr<'hir>{
2106+
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
21072107
let lit = hir::Lit{
21082108
span:self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super)fnexpr_usize(&mutself,sp:Span,value:usize) -> hir::Expr<'hir>{
2115-
self.expr_uint(sp, ast::UintTy::Usize, value asu128)
2116-
}
2117-
2118-
pub(super)fnexpr_u32(&mutself,sp:Span,value:u32) -> hir::Expr<'hir>{
2119-
self.expr_uint(sp, ast::UintTy::U32, value asu128)
2120-
}
2121-
2122-
pub(super)fnexpr_u16(&mutself,sp:Span,value:u16) -> hir::Expr<'hir>{
2123-
self.expr_uint(sp, ast::UintTy::U16, value asu128)
2124-
}
2125-
2126-
pub(super)fnexpr_str(&mutself,sp:Span,value:Symbol) -> hir::Expr<'hir>{
2114+
pub(super)fnexpr_byte_str(&mutself,sp:Span,value:ByteSymbol) -> hir::Expr<'hir>{
21272115
let lit = hir::Lit{
21282116
span:self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fnexpr_unsafe(&mutself,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
2253+
pub(super)fnexpr_unsafe(
2254+
&mutself,
2255+
span:Span,
2256+
expr:&'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir>{
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super)fnexpr_array_ref(
2306-
&mutself,
2307-
span:Span,
2308-
elements:&'hir[hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir>{
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super)fnexpr_ref(&mutself,span:Span,expr:&'hir hir::Expr<'hir>) -> hir::Expr<'hir>{
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)