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

libsyntax: Name can be made NonZero #28657

Closed
petrochenkov opened this issue Sep 25, 2015 · 9 comments
Closed

libsyntax: Name can be made NonZero #28657

petrochenkov opened this issue Sep 25, 2015 · 9 comments
Labels
A-parser Area: The parsing of Rust source code to an AST

Comments

@petrochenkov
Copy link
Contributor

Spawned from #28642

Name is an index into the string interner's internal array. The first element of this array can be reserved and Name will always contain non-zero index. It will make Option<Name> and Option<Ident> commonly encountered in AST/HIR more compact.
Requires const unsafe functions.

@steveklabnik steveklabnik added the A-parser Area: The parsing of Rust source code to an AST label Sep 28, 2015
@oli-obk
Copy link
Contributor

oli-obk commented Jan 14, 2016

Requires a snapshot after #30899 is merged. Otherwise matching on a builtin keyword name will fail to compile due to code in libsyntax calling the const fn NonZero::new which is in libcore.

Alternatively we can start to eagerly evaluate pub consts and put the ConstVal into the metadata instead of the expression making up the contant. But that's probably definitely a breaking change and should probably wait on MIR const eval.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2016

ok it's merged. Now we just need to wait for the next snapshot. cc @alexcrichton

@alexcrichton
Copy link
Member

It may be a bit before we get a new snapshot, so I might recommend some #[cfg(stage0)] trickery to make this usable in stage0 (if possible)

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2016

That would be way too messy. It's already a huge crowd of macros that's generating these definitions. I'll just wait until the next snapshot. It's not like this is a critical change.

@petrochenkov
Copy link
Contributor Author

This issue is not important or urgent, it can wait as long as necessary and doesn't worth the stage0 dance.
I don't even know if memory savings will be observable or not.

@pnkfelix
Copy link
Member

Also, before we start throwing the NonZero wrapper everywhere, I would like some serious consideration to be given to #31217

@petrochenkov
Copy link
Contributor Author

I've implemented this and there's no observable difference in consumed memory or compilation times, and more unsafe than I'd like to see.
I think I'll just close this issue.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented May 15, 2016

Nah, it doesn't make difference for most of crates, but consistently reduces memory consumption for the two largest crates - librustc and libsyntax (the runs are intermingled):

librustc before, run 1

rustc: x86_64-pc-windows-gnu/stage1/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc
time: 0.246; rss: 78MB parsing
time: 0.083; rss: 79MB configuration 1
time: 0.000; rss: 79MB recursion limit
time: 0.000; rss: 79MB crate injection
time: 0.017; rss: 80MB macro loading
time: 0.000; rss: 80MB plugin loading
time: 0.000; rss: 80MB plugin registration
time: 1.086; rss: 127MB expansion
time: 0.201; rss: 127MB configuration 2
time: 0.000; rss: 127MB gated configuration checking
time: 0.096; rss: 127MB maybe building test harness
time: 0.089; rss: 128MB prelude injection
time: 0.017; rss: 128MB checking that all macro invocations are gone
time: 0.000; rss: 128MB checking for inline asm in case the target doesn't support it
time: 0.037; rss: 128MB complete gated feature checking
time: 0.079; rss: 128MB assigning node ids
time: 0.052; rss: 137MB collecting defs
time: 0.030; rss: 154MB external crate/lib resolution
time: 0.073; rss: 154MB early lint checks
time: 0.294; rss: 204MB name resolution
time: 0.152; rss: 289MB lowering ast -> hir
time: 0.020; rss: 286MB indexing hir
time: 0.015; rss: 286MB attribute checking
time: 0.012; rss: 253MB language item collection
time: 0.021; rss: 254MB lifetime resolution
time: 0.000; rss: 254MB looking for entry point
time: 0.000; rss: 254MB looking for plugin registrar
time: 0.093; rss: 277MB region resolution
time: 0.013; rss: 277MB loop checking
time: 0.013; rss: 277MB static item recursion checking
time: 0.000; rss: 277MB load_dep_graph
time: 0.083; rss: 296MB type collecting
time: 0.002; rss: 296MB variance inference
time: 0.076; rss: 309MB coherence checking
time: 0.468; rss: 314MB wf checking
time: 0.255; rss: 316MB item-types checking
time: 9.156; rss: 379MB item-bodies checking
time: 0.000; rss: 379MB drop-impl checking
time: 0.751; rss: 382MB const checking
time: 0.153; rss: 382MB privacy checking
time: 0.026; rss: 383MB stability index
time: 0.075; rss: 383MB intrinsic checking
time: 0.040; rss: 383MB effect checking
time: 0.200; rss: 383MB match checking
time: 0.107; rss: 383MB liveness checking
time: 0.665; rss: 383MB rvalue checking
time: 0.955; rss: 526MB MIR dump
time: 0.594; rss: 520MB MIR passes
time: 1.396; rss: 524MB borrow checking
time: 0.056; rss: 525MB reachability checking
time: 0.115; rss: 526MB death checking
time: 0.094; rss: 528MB stability checking
time: 0.000; rss: 528MB unused lib feature checking
time: 0.501; rss: 528MB lint checking
time: 0.002; rss: 528MB resolving dependency formats
time: 0.191; rss: 543MB Prepare MIR codegen passes
time: 2.107; rss: 578MB translation item collection
time: 0.290; rss: 582MB codegen unit partitioning
time: 1.361; rss: 1274MB write metadata
time: 14.256; rss: 1124MB translation
time: 0.003; rss: 1124MB assert dep graph
time: 0.000; rss: 1124MB serialize dep graph
time: 2.792; rss: 663MB llvm function passes [0]
time: 51.822; rss: 812MB llvm module passes [0]
time: 14.811; rss: 811MB codegen passes [0]
time: 0.020; rss: 179MB codegen passes [0]
time: 70.745; rss: 170MB LLVM passes
time: 0.745; rss: 170MB running linker
time: 1.492; rss: 172MB linking

librustc before, run 2

rustc: x86_64-pc-windows-gnu/stage1/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc
time: 0.226; rss: 78MB parsing
time: 0.075; rss: 79MB configuration 1
time: 0.000; rss: 79MB recursion limit
time: 0.000; rss: 79MB crate injection
time: 0.018; rss: 81MB macro loading
time: 0.000; rss: 81MB plugin loading
time: 0.000; rss: 81MB plugin registration
time: 1.101; rss: 127MB expansion
time: 0.200; rss: 127MB configuration 2
time: 0.000; rss: 127MB gated configuration checking
time: 0.095; rss: 127MB maybe building test harness
time: 0.082; rss: 128MB prelude injection
time: 0.016; rss: 128MB checking that all macro invocations are gone
time: 0.000; rss: 128MB checking for inline asm in case the target doesn't support it
time: 0.032; rss: 128MB complete gated feature checking
time: 0.079; rss: 128MB assigning node ids
time: 0.053; rss: 137MB collecting defs
time: 0.028; rss: 154MB external crate/lib resolution
time: 0.075; rss: 154MB early lint checks
time: 0.289; rss: 204MB name resolution
time: 0.150; rss: 289MB lowering ast -> hir
time: 0.021; rss: 286MB indexing hir
time: 0.017; rss: 286MB attribute checking
time: 0.016; rss: 253MB language item collection
time: 0.025; rss: 254MB lifetime resolution
time: 0.000; rss: 254MB looking for entry point
time: 0.000; rss: 254MB looking for plugin registrar
time: 0.098; rss: 277MB region resolution
time: 0.015; rss: 277MB loop checking
time: 0.015; rss: 277MB static item recursion checking
time: 0.000; rss: 277MB load_dep_graph
time: 0.084; rss: 296MB type collecting
time: 0.003; rss: 296MB variance inference
time: 0.081; rss: 309MB coherence checking
time: 0.463; rss: 314MB wf checking
time: 0.255; rss: 316MB item-types checking
time: 9.399; rss: 379MB item-bodies checking
time: 0.000; rss: 379MB drop-impl checking
time: 0.765; rss: 383MB const checking
time: 0.132; rss: 383MB privacy checking
time: 0.022; rss: 383MB stability index
time: 0.081; rss: 383MB intrinsic checking
time: 0.035; rss: 383MB effect checking
time: 0.203; rss: 383MB match checking
time: 0.110; rss: 383MB liveness checking
time: 0.700; rss: 383MB rvalue checking
time: 0.997; rss: 527MB MIR dump
time: 0.630; rss: 520MB MIR passes
time: 1.469; rss: 524MB borrow checking
time: 0.054; rss: 525MB reachability checking
time: 0.104; rss: 526MB death checking
time: 0.089; rss: 528MB stability checking
time: 0.000; rss: 528MB unused lib feature checking
time: 0.545; rss: 528MB lint checking
time: 0.002; rss: 528MB resolving dependency formats
time: 0.186; rss: 543MB Prepare MIR codegen passes
time: 2.161; rss: 578MB translation item collection
time: 0.283; rss: 582MB codegen unit partitioning
time: 1.351; rss: 1274MB write metadata
time: 14.323; rss: 1125MB translation
time: 0.003; rss: 1125MB assert dep graph
time: 0.000; rss: 1125MB serialize dep graph
time: 2.747; rss: 665MB llvm function passes [0]
time: 51.816; rss: 814MB llvm module passes [0]
time: 15.055; rss: 831MB codegen passes [0]
time: 0.021; rss: 181MB codegen passes [0]
time: 70.962; rss: 172MB LLVM passes
time: 0.792; rss: 172MB running linker
time: 1.444; rss: 174MB linking

librustc after, run 1

rustc: x86_64-pc-windows-gnu/stage1/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc
time: 0.233; rss: 78MB parsing
time: 0.085; rss: 79MB configuration 1
time: 0.000; rss: 79MB recursion limit
time: 0.000; rss: 79MB crate injection
time: 0.018; rss: 81MB macro loading
time: 0.000; rss: 81MB plugin loading
time: 0.000; rss: 81MB plugin registration
time: 1.062; rss: 128MB expansion
time: 0.214; rss: 128MB configuration 2
time: 0.000; rss: 128MB gated configuration checking
time: 0.094; rss: 128MB maybe building test harness
time: 0.085; rss: 128MB prelude injection
time: 0.015; rss: 128MB checking that all macro invocations are gone
time: 0.000; rss: 128MB checking for inline asm in case the target doesn't support it
time: 0.033; rss: 128MB complete gated feature checking
time: 0.081; rss: 128MB assigning node ids
time: 0.053; rss: 137MB collecting defs
time: 0.030; rss: 155MB external crate/lib resolution
time: 0.070; rss: 155MB early lint checks
time: 0.292; rss: 204MB name resolution
time: 0.161; rss: 288MB lowering ast -> hir
time: 0.020; rss: 285MB indexing hir
time: 0.016; rss: 285MB attribute checking
time: 0.013; rss: 233MB language item collection
time: 0.022; rss: 234MB lifetime resolution
time: 0.000; rss: 234MB looking for entry point
time: 0.000; rss: 234MB looking for plugin registrar
time: 0.087; rss: 258MB region resolution
time: 0.012; rss: 258MB loop checking
time: 0.014; rss: 258MB static item recursion checking
time: 0.000; rss: 258MB load_dep_graph
time: 0.082; rss: 279MB type collecting
time: 0.002; rss: 279MB variance inference
time: 0.076; rss: 292MB coherence checking
time: 0.466; rss: 298MB wf checking
time: 0.272; rss: 299MB item-types checking
time: 9.115; rss: 363MB item-bodies checking
time: 0.000; rss: 363MB drop-impl checking
time: 0.786; rss: 366MB const checking
time: 0.154; rss: 366MB privacy checking
time: 0.026; rss: 366MB stability index
time: 0.075; rss: 366MB intrinsic checking
time: 0.041; rss: 366MB effect checking
time: 0.203; rss: 366MB match checking
time: 0.110; rss: 368MB liveness checking
time: 0.716; rss: 368MB rvalue checking
time: 0.963; rss: 509MB MIR dump
time: 0.599; rss: 503MB MIR passes
time: 1.437; rss: 508MB borrow checking
time: 0.056; rss: 508MB reachability checking
time: 0.115; rss: 509MB death checking
time: 0.095; rss: 511MB stability checking
time: 0.000; rss: 511MB unused lib feature checking
time: 0.503; rss: 511MB lint checking
time: 0.002; rss: 511MB resolving dependency formats
time: 0.192; rss: 525MB Prepare MIR codegen passes
time: 2.086; rss: 561MB translation item collection
time: 0.285; rss: 564MB codegen unit partitioning
time: 1.315; rss: 1257MB write metadata
time: 14.155; rss: 1113MB translation
time: 0.003; rss: 1113MB assert dep graph
time: 0.000; rss: 1113MB serialize dep graph
time: 2.694; rss: 663MB llvm function passes [0]
time: 51.442; rss: 812MB llvm module passes [0]
time: 14.843; rss: 829MB codegen passes [0]
time: 0.020; rss: 179MB codegen passes [0]
time: 70.328; rss: 170MB LLVM passes
time: 0.751; rss: 171MB running linker
time: 1.422; rss: 172MB linking

librustc after, run 2

rustc: x86_64-pc-windows-gnu/stage1/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc
time: 0.225; rss: 78MB parsing
time: 0.081; rss: 79MB configuration 1
time: 0.000; rss: 79MB recursion limit
time: 0.000; rss: 79MB crate injection
time: 0.018; rss: 81MB macro loading
time: 0.000; rss: 81MB plugin loading
time: 0.000; rss: 81MB plugin registration
time: 1.056; rss: 128MB expansion
time: 0.200; rss: 128MB configuration 2
time: 0.000; rss: 128MB gated configuration checking
time: 0.093; rss: 128MB maybe building test harness
time: 0.086; rss: 128MB prelude injection
time: 0.017; rss: 128MB checking that all macro invocations are gone
time: 0.000; rss: 128MB checking for inline asm in case the target doesn't support it
time: 0.036; rss: 128MB complete gated feature checking
time: 0.077; rss: 128MB assigning node ids
time: 0.052; rss: 137MB collecting defs
time: 0.031; rss: 155MB external crate/lib resolution
time: 0.075; rss: 155MB early lint checks
time: 0.289; rss: 204MB name resolution
time: 0.173; rss: 288MB lowering ast -> hir
time: 0.025; rss: 285MB indexing hir
time: 0.018; rss: 285MB attribute checking
time: 0.015; rss: 233MB language item collection
time: 0.027; rss: 234MB lifetime resolution
time: 0.000; rss: 234MB looking for entry point
time: 0.000; rss: 234MB looking for plugin registrar
time: 0.099; rss: 258MB region resolution
time: 0.015; rss: 258MB loop checking
time: 0.015; rss: 258MB static item recursion checking
time: 0.000; rss: 258MB load_dep_graph
time: 0.084; rss: 279MB type collecting
time: 0.003; rss: 279MB variance inference
time: 0.080; rss: 292MB coherence checking
time: 0.449; rss: 298MB wf checking
time: 0.258; rss: 299MB item-types checking
time: 8.997; rss: 363MB item-bodies checking
time: 0.000; rss: 363MB drop-impl checking
time: 0.767; rss: 366MB const checking
time: 0.151; rss: 366MB privacy checking
time: 0.026; rss: 366MB stability index
time: 0.074; rss: 366MB intrinsic checking
time: 0.039; rss: 366MB effect checking
time: 0.198; rss: 366MB match checking
time: 0.114; rss: 368MB liveness checking
time: 0.696; rss: 368MB rvalue checking
time: 0.967; rss: 510MB MIR dump
time: 0.596; rss: 503MB MIR passes
time: 1.405; rss: 508MB borrow checking
time: 0.056; rss: 508MB reachability checking
time: 0.113; rss: 509MB death checking
time: 0.093; rss: 511MB stability checking
time: 0.000; rss: 511MB unused lib feature checking
time: 0.505; rss: 511MB lint checking
time: 0.002; rss: 511MB resolving dependency formats
time: 0.192; rss: 526MB Prepare MIR codegen passes
time: 2.088; rss: 561MB translation item collection
time: 0.283; rss: 564MB codegen unit partitioning
time: 1.316; rss: 1257MB write metadata
time: 14.060; rss: 1113MB translation
time: 0.003; rss: 1113MB assert dep graph
time: 0.000; rss: 1113MB serialize dep graph
time: 2.678; rss: 664MB llvm function passes [0]
time: 51.088; rss: 812MB llvm module passes [0]
time: 14.778; rss: 811MB codegen passes [0]
time: 0.020; rss: 178MB codegen passes [0]
time: 69.879; rss: 170MB LLVM passes
time: 0.714; rss: 170MB running linker
time: 1.355; rss: 172MB linking

The difference is up to 20MB/7-8% before type checking! I'll try to reduce the amount of `unsafe`ty and submit a PR after all.

@petrochenkov petrochenkov reopened this May 15, 2016
@petrochenkov
Copy link
Contributor Author

The difference is up to 20MB/7-8% before type checking!

Well, now I can't reproduce it. Let's consider this a fluctuation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

5 participants