Skip to content

Commit

Permalink
optimisation
Browse files Browse the repository at this point in the history
Summary: An micro-optimisation: if a type alias has no parameters, there is no reason to go with an empty substitution and the body can be just re-used

Reviewed By: TD5

Differential Revision: D69180282

fbshipit-source-id: a47a7776bac0bddb96008a47dc7f361382c2156f
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Feb 5, 2025
1 parent b26c920 commit 6612edd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions crates/eqwalizer/src/ast/contractivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ impl StubContractivityChecker<'_> {
.expanded_stub(self.project_id, ModuleName::new(id.module.as_str()))
.map_err(|err| ContractivityCheckError::ErrorExpandingID(id.clone(), Box::new(err)))?;
fn subst(decl: &TypeDecl, args: &[Type]) -> Type {
let sub: FxHashMap<u32, &Type> =
decl.params.iter().map(|v| v.n).zip(args.iter()).collect();
Subst { sub }.apply(decl.body.clone())
if decl.params.is_empty() {
decl.body.clone()
} else {
let sub: FxHashMap<u32, &Type> =
decl.params.iter().map(|v| v.n).zip(args.iter()).collect();
Subst { sub }.apply(decl.body.clone())
}
}
Ok(stub
.types
Expand Down
10 changes: 7 additions & 3 deletions crates/eqwalizer/src/ast/variance_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,13 @@ impl VarianceChecker<'_> {
.contractive_stub(self.project_id, ModuleName::new(id.module.as_str()))
.map_err(|err| VarianceCheckError::ErrorExpandingID(id.clone(), Box::new(err)))?;
fn subst(decl: &TypeDecl, args: &[Type]) -> Type {
let sub: FxHashMap<u32, &Type> =
decl.params.iter().map(|v| v.n).zip(args.iter()).collect();
Subst { sub }.apply(decl.body.clone())
if decl.params.is_empty() {
decl.body.clone()
} else {
let sub: FxHashMap<u32, &Type> =
decl.params.iter().map(|v| v.n).zip(args.iter()).collect();
Subst { sub }.apply(decl.body.clone())
}
}
Ok(stub.types.get(&local_id).map(|t| subst(t, args)))
}
Expand Down

0 comments on commit 6612edd

Please sign in to comment.