Skip to content

Upgrade Chalk #2872

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

Merged
merged 3 commits into from
Jan 27, 2020
Merged

Upgrade Chalk #2872

merged 3 commits into from
Jan 27, 2020

Conversation

flodiebold
Copy link
Member

@flodiebold flodiebold commented Jan 17, 2020

This is just keeping track of the changes required to upgrade Chalk; currently we can't really merge it since it breaks opaque types.

Now also makes use of the newly introduced solve_limited to implement fuel.

@jackh726
Copy link
Member

Along with this, I would also suggest changing the CHALK_SOLVER_MAX_SIZE to 10 (which should be possible now that solve_limited is added) and/or testing out my branch. Either of these should fix a couple issues. Unfortunately, I don't know when impl Trait will be back (@detrumi said he's gonna try to implement it), so tbh I would try to not block on it.

@flodiebold flodiebold marked this pull request as ready for review January 27, 2020 20:53
@flodiebold
Copy link
Member Author

r? @matklad

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "chalk-macros"
version = "0.1.1"
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should switch this to OnceCell :D

@flodiebold
Copy link
Member Author

bors r=matklad

bors bot added a commit that referenced this pull request Jan 27, 2020
2872: Upgrade Chalk r=matklad a=flodiebold

This is just keeping track of the changes required to upgrade Chalk; currently we can't really merge it since it breaks opaque types.

Now also makes use of the newly introduced `solve_limited` to implement fuel.

Co-authored-by: Florian Diebold <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jan 27, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • Rust (windows-latest)
  • TypeScript

@bors bors bot merged commit 339a11c into rust-lang:master Jan 27, 2020
@flodiebold flodiebold deleted the chalk-upgrade branch January 27, 2020 21:37
@matklad
Copy link
Member

matklad commented Jan 28, 2020

I've tried running again on the substrate repo. It eventually OOMs, but looks like this is because we genuinely don't cleanup various caches, and not because some particular functions leads to O(infinity) allocations.

@flodiebold
Copy link
Member Author

Does the fuel not prevent that?

@matklad
Copy link
Member

matklad commented Jan 28, 2020

I don't understand why you are asking this question :) Basically, after we type check each function, we seem to leave some stuff allocated behind (inside chalk caches, or maybe the InferenceResult itself), and it seems like after approximatelly 5k functions that adds up to more than 16 GB :)

@flodiebold
Copy link
Member Author

Oh, I somehow thought the problem was one big Chalk query, not many small ones...

@flodiebold
Copy link
Member Author

It's still a bit weird though -- I don't think Chalk memory usage should scale directly with the number of functions, more with the number of types and traits 🤔

@jackh726
Copy link
Member

This is interesting. It doesn't really surprise me that memory scales with functions, considering each one would generate a new Goal, which makes a new Table, which stores all potential Strands. It would be good to think about this going forward.

@flodiebold
Copy link
Member Author

@jackh726 Shouldn't there be a table per unique goal? Although I didn't consider environments, which might lead to enough combinations to cause this 🤔

@matklad
Copy link
Member

matklad commented Jan 28, 2020 via email

@jackh726
Copy link
Member

@flodiebold Yes, it is per unique goal. I sort of assumed that almost every goal would be different because of different signatures. But yeah, different environments too :/ (actually now that I think about it, that would be something interesting to try "delaying" until the root goal, so sub-goals are shared)

@matklad
Copy link
Member

matklad commented Jan 29, 2020

Here's what I've got:

Inference: 135.902349975s, 11618mb allocated 11960mb resident
Total: 162.096771519s, 11618mb allocated 11960mb resident
  1702mb TraitSolveQuery (deps)
   522mb ImplDatumQuery (deps)
   449mb MacroArgQuery
   359mb ImplDatumQuery
   293mb ComputeCrateDefMapQuery
   113mb ImplsForTraitQuery (deps)
    76mb RawItemsQuery
    56mb DoInferQuery (deps)
    50mb BodyQuery
    44mb DoInferQuery
    38mb ImplDataQuery
    35mb ImplDataQuery (deps)
    34mb GenericParamsQuery (deps)
    33mb ImplsForTraitQuery
    28mb GenericParamsQuery
    24mb AstIdMapQuery (deps)
    24mb MacroExpandQuery (deps)
    24mb MacroArgQuery (deps)
    23mb ParseMacroQuery (deps)
    22mb MacroDefQuery
    21mb BodyWithSourceMapQuery
    20mb GenericPredicatesQuery (deps)
    18mb RawItemsQuery (deps)
    16mb ParseQuery
    16mb ComputeCrateDefMapQuery (deps)
    12mb AstIdMapQuery
     9mb TyQuery (deps)
     6mb FunctionDataQuery
     6mb GenericDefaultsQuery (deps)
     5mb ExprScopesQuery
     4mb GenericPredicatesQuery
     4mb ImplsInCrateQuery (deps)
     4mb ParseMacroQuery
     4mb BodyWithSourceMapQuery (deps)
  3686kb MacroExpandQuery
  2969kb CallableItemSignatureQuery (deps)
  2753kb FunctionDataQuery (deps)
  2492kb TypeAliasDataQuery (deps)
  2407kb TypeAliasDataQuery
  2315kb TyQuery
  1917kb BodyQuery (deps)
  1910kb ParseQuery (deps)
  1582kb ImplsInCrateQuery
  1553kb StructDatumQuery (deps)
  1446kb ExprScopesQuery (deps)
  1368kb CallableItemSignatureQuery
  1270kb TraitDatumQuery
  1186kb ValueTyQuery (deps)
  1020kb TraitDatumQuery (deps)
   897kb GenericDefaultsQuery
   719kb TraitSolveQuery
   687kb EnumDataQuery
   684kb StructDatumQuery
   653kb FieldTypesQuery (deps)
   602kb StructDataQuery
   599kb ModuleLangItemsQuery (deps)
   392kb MacroDefQuery (deps)
   348kb FieldTypesQuery
   283kb TraitDataQuery (deps)
   229kb ValueTyQuery
   204kb StructDataQuery (deps)
   200kb LangItemQuery (deps)
   179kb TraitDataQuery
   133kb EnumDataQuery (deps)
   114kb ConstDataQuery (deps)
   110kb AssociatedTyDataQuery (deps)
    72kb CrateLangItemsQuery (deps)
    62kb ConstDataQuery
    23kb AssociatedTyDataQuery
   4096b CrateLangItemsQuery
      0b SourceRootCratesQuery
      0b SourceRootCratesQuery (deps)
      0b StaticDataQuery
      0b StaticDataQuery (deps)
      0b ModuleLangItemsQuery
      0b LangItemQuery
      0b DocumentationQuery
      0b DocumentationQuery (deps)
      0b TraitSolverQuery
      0b TraitSolverQuery (deps)
leftover: 7472mb

TL;DR: it's mostly salsa's dependencies. And also 7.5 gigabytes of something else :)

@matklad
Copy link
Member

matklad commented Jan 29, 2020

The huge leftower is due to the fact that salsa does not collect interned queries by default. Here's how it looks like with full collection

Inference: 115.100410267s, 6346mb allocated 6563mb resident
Total: 141.769638795s, 6346mb allocated 6563mb resident
  1870mb TraitSolverQuery
  1455mb TraitSolveQuery (deps)
   505mb MacroArgQuery
   470mb ImplDatumQuery (deps)
   308mb ImplDatumQuery
   293mb ComputeCrateDefMapQuery
    93mb ImplsForTraitQuery (deps)
    76mb RawItemsQuery
    52mb BodyQuery
    51mb DoInferQuery (deps)
    43mb DoInferQuery
    42mb ImplTraitQuery (deps)
    41mb ImplSelfTyQuery (deps)
    38mb ImplDataQuery
    38mb ImplDataQuery (deps)
    33mb GenericParamsQuery (deps)
    33mb ImplsForTraitQuery
    31mb AssociatedTyValueQuery (deps)
    26mb GenericParamsQuery
    25mb AstIdMapQuery (deps)
    24mb MacroArgQuery (deps)
    24mb ParseMacroQuery (deps)
    23mb MacroExpandQuery (deps)
    22mb MacroDefQuery
    21mb BodyWithSourceMapQuery
    19mb GenericPredicatesQuery (deps)
    18mb RawItemsQuery (deps)
    18mb ComputeCrateDefMapQuery (deps)
    15mb ParseQuery
    12mb AssociatedTyValueQuery
    12mb AstIdMapQuery
     9mb TyQuery (deps)
     8mb ImplTraitQuery
     7mb InternFunctionQuery
     7mb BodyWithSourceMapQuery (deps)
     7mb GenericDefaultsQuery (deps)
     5mb FunctionDataQuery
     5mb ExprScopesQuery
     4mb AttrsQuery (deps)
     4mb ImplsInCrateQuery (deps)
     4mb GenericPredicatesQuery
     4mb AttrsQuery
  4076kb InternConstQuery
  2628kb TypeAliasDataQuery
  2484kb TypeAliasDataQuery (deps)
  2475kb CallableItemSignatureQuery (deps)
  2433kb FunctionDataQuery (deps)
  2351kb TyQuery
  2069kb BodyQuery (deps)
  1885kb ParseQuery (deps)
  1604kb TraitDatumQuery (deps)
  1470kb ExprScopesQuery (deps)
  1416kb TraitDatumQuery
  1288kb StructDataQuery
  1262kb EnumDataQuery
  1181kb StructDatumQuery (deps)
  1113kb CallableItemSignatureQuery
  1088kb ImplsInCrateQuery
  1045kb InternTypeAliasQuery
  1018kb GenericPredicatesForParamQuery (deps)
  1017kb ValueTyQuery (deps)
   859kb GenericDefaultsQuery
   746kb StructDatumQuery
   701kb ParseMacroQuery
   586kb FieldTypesQuery (deps)
   554kb ImplSelfTyQuery
   541kb MacroDefQuery (deps)
   534kb ModuleLangItemsQuery (deps)
   487kb TraitSolveQuery
   410kb GenericPredicatesForParamQuery
   290kb FieldTypesQuery
   258kb TraitDataQuery (deps)
   239kb ValueTyQuery
   188kb StructDataQuery (deps)
   186kb LangItemQuery (deps)
   160kb InternImplQuery
   139kb EnumDataQuery (deps)
   130kb TraitDataQuery
   114kb AssociatedTyDataQuery (deps)
    85kb ConstDataQuery (deps)
    68kb InternStructQuery
    48kb ConstDataQuery
    47kb CrateLangItemsQuery (deps)
    44kb InternStaticQuery
    40kb InternEnumQuery
    36kb MacroExpandQuery
    35kb AssociatedTyDataQuery
    15kb StaticDataQuery (deps)
     8kb InternTraitQuery
   4096b StaticDataQuery
   4096b ModuleLangItemsQuery
   4096b CrateLangItemsQuery
      0b Synthetic Write
      0b SourceRootCratesQuery
      0b SourceRootCratesQuery (deps)
      0b InternMacroQuery
      0b InternMacroQuery (deps)
      0b UnionDataQuery
      0b UnionDataQuery (deps)
      0b LangItemQuery
      0b DocumentationQuery
      0b DocumentationQuery (deps)
      0b InternFunctionQuery (deps)
      0b InternStructQuery (deps)
      0b InternUnionQuery
      0b InternUnionQuery (deps)
      0b InternEnumQuery (deps)
      0b InternConstQuery (deps)
      0b InternStaticQuery (deps)
      0b InternTraitQuery (deps)
      0b InternTypeAliasQuery (deps)
      0b InternImplQuery (deps)
      0b TraitSolverQuery (deps)
      0b InternTypeCtorQuery
      0b InternTypeCtorQuery (deps)
      0b InternChalkImplQuery
      0b InternChalkImplQuery (deps)
      0b InternAssocTyValueQuery
      0b InternAssocTyValueQuery (deps)
leftover: 488mb

Note that TraitSolverQuery (that is, the chalk solver struct itself) went from 0 to 1870mb, which I can't really explain

@matklad
Copy link
Member

matklad commented Jan 29, 2020

opened #2945 with a slightly bigger trace

@bkchr bkchr mentioned this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants