Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jez
Copy link
Collaborator

@jez jez commented Mar 30, 2022

Motivation

This will allow us to make more progress on #5469 (LSP queries on stale state)

Commit summary

Your best bet is to review by commit, ignoring whitespace.

  • Move computeLinearization to GlobalState (1859b30)

  • pre-work: Use lambda for better clang-format (9a2d590)

  • computeLinearization in GlobalState::initEmpty (7303377)

    This should be safe--if we ever call addMixin after this, we will reset
    the linearization status on that class.

    This allows us to call verifyLinearizationComputed in
    runIncrementalBestEffort (because our test suite tests an edge case
    where we run runIncrementalBestEffort with --no-stdlib so Resolver
    truly has never been run before).

  • Non-mutating version of resolveConstants (6c7fd4e)

    Mostly uses the technique that froydnj established in add a non-mutating incremental resolver interface #5456.

  • Rest of the failures (598d5ed)

Test plan

This calls the immutable incremental resolver immediately after the immutable
namer and enables all ENFORCEs and sanityChecks, so that we can use our existing
test suite as a test of how well these modes work.

jez added 5 commits March 29, 2022 18:37
This should be safe--if we ever call addMixin after this, we will reset
the linearization status on that class.

This allows us to call `verifyLinearizationComputed` in
`runIncrementalBestEffort` (because our test suite tests an edge case
where we run `runIncrementalBestEffort` with `--no-stdlib` so Resolver
truly has never been run before).
Mostly uses the technique that froydnj established in #5456.
@jez jez requested a review from a team as a code owner March 30, 2022 03:01
@jez jez requested review from elliottt and removed request for a team March 30, 2022 03:01
Symbols::MAX_SYNTHETIC_TYPEARGUMENT_SYMBOLS);

installIntrinsics();
computeLinearization();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Motivation is also in this commit message:

This should be safe--if we ever call addMixin after this, we will reset
the linearization status on that class.

This allows us to call `verifyLinearizationComputed` in
`runIncrementalBestEffort` (because our test suite tests an edge case
where we run `runIncrementalBestEffort` with `--no-stdlib` so Resolver
truly has never been run before).

vector<ast::ParsedFile> trees) {
auto workers = WorkerPool::create(0, gs.tracer());
// trees = ResolveConstantsWalk::resolveConstants(gs, std::move(trees), *workers);
trees = ResolveConstantsWalk::resolveConstants(gs, std::move(trees), *workers);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was accidentally commented out in the original change. It's quite important that it not be commented out (this is basically all the work that resolver does 😅 )

Comment on lines +1629 to +1631
// If the constant didn't immediately resolve during the initial treewalk, and we're not
// allowed to mutate GlobalState, it will never resolve. Let's just skip to the error phase.
if constexpr (isMutableStateType) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the key insight that makes this change workable at all, and not immeasurably hairy.

The ResolveConstantsWalk will try to avoid enqueuing work into the various todo lists for the sake of speed. That means that if there's anything in the todo lists at the end of the loop, they're there because they were hoping to be resolved / processed once some other todo list item had been processed.

But we won't actually be able to make progress. Making progress requires being able to modify the symbol table, so that other items can discover new state in the symbol table and make their own progress. That will never happen in the immutable resolver mode, so we can skip straight to the final part.

// If no ENFORCE fired, then non-mutating namer is working fine.
treesCopy = move(resolver::Resolver::runIncremental(immutableGS, move(treesCopy)).result());

// If no ENFORCE fired, then immutatable namer + resolver is working fine.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've just realized that we probably want to run DefLocSaver and typecheckOne on these resolved trees. Both of those operate on immutable GlobalState already, so it's just a question of do our namer and resolver passes do a good enough job at cleaning up the trees.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was the intent here to ensure that we're able to answer LSP queries when using a stale global state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep!

@jez jez enabled auto-merge (squash) March 31, 2022 22:09
@jez jez merged commit da662f8 into master Mar 31, 2022
@jez jez deleted the jez-const-resolver-v2 branch March 31, 2022 22:29
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