Skip to content

Commit

Permalink
Reduce allocs by making SmartConstructors stateful
Browse files Browse the repository at this point in the history
Summary:
Major refactoring of the parser in hope of squeezing
noticeable gains by not passing around SmartConstructors state.

Basically, replace the following:

  make_XYZ(state: State, ...) -> (State, R)

with

  make_XYZ(&mut self, ...) -> R

and make each of the 5 implementors of SmartConstructors stateful
by turning the old method `initial_state(...)` into constructor `new`.

Unfortunately, this means more boilerplate in the **user code**
(i.e., implementors of SmartConstructors):
- implementing Clone for each implementor of StateType
- implementing Clone for each implementor of SmartConstructors

this *cannot* be auto-generated via `#[derive(Clone)` because of
the [`PhantomData`](rust-lang/rust#29005 (comment)) that is needed to narrow down trait impl of `StateType`.

Reviewed By: shiqicao

Differential Revision: D16374645

fbshipit-source-id: 37c248e70d93dd505e5478a57b646ad469907d7c
  • Loading branch information
losvald authored and hhvm-bot committed Jul 23, 2019
1 parent 9ac0292 commit 1d2ef67
Show file tree
Hide file tree
Showing 24 changed files with 3,996 additions and 4,166 deletions.
2 changes: 1 addition & 1 deletion hphp/hack/src/facts/facts_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use parser::source_text::SourceText;
use crate::facts::*;
use crate::facts_smart_constructors::*;

pub type FactsParser<'a> = Parser<'a, WithKind<FactsSmartConstructors>, HasScriptContent<'a>>;
pub type FactsParser<'a> = Parser<'a, WithKind<FactsSmartConstructors<'a>>, HasScriptContent<'a>>;

pub struct ExtractAsJsonOpts {
pub php5_compat_mode: bool,
Expand Down
Loading

0 comments on commit 1d2ef67

Please sign in to comment.