Skip to content

[NameLookup] Ensure extensions are updated after module load #32375

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

Conversation

hamishknight
Copy link
Contributor

Call prepareExtensions in prepareLookupTable to make sure we load in any new extensions brought in by modules loaded after-the-fact. This isn't an issue for normal compilations as we load all the modules up-front in import resolution, but clients such as the LLDB REPL may load in modules later.

As the LLDB REPL appears to be the only client affected by this, the test case is in swiftlang/llvm-project#1338.

Resolves rdar://64040436.

@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#1338

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight hamishknight requested a review from CodaFi June 15, 2020 16:15
@CodaFi
Copy link
Contributor

CodaFi commented Jun 15, 2020

Isn't this exploiting this problem?

    // FIXME: If disableAdditionalExtensionLoading is true, we should
    // not mark the entry as complete.
    Table.markLazilyComplete(baseName);

Can we fix this bug by moving the marking under the condition above?

@hamishknight
Copy link
Contributor Author

@CodaFi Unfortunately that doesn't fix it (though I can include it in this patch if you want) – in this case we initially do a member lookup, which loads in and looks through extensions, and marks the table lazily complete for that name. We then load a module, but because the table is already marked lazily complete, any further lookups bail with the previous set of results.

That being said, I totally forgot we had the IgnoreNewExtensions flag, we could optimize this fix slightly by doing:

if (!disableAdditionalExtensionLoading)
  decl->prepareExtensions();

How does that sound?

@CodaFi
Copy link
Contributor

CodaFi commented Jun 15, 2020

Should we just invalidate the lookup caches when performing a module load, then? (I would have expected binding new extensions to already handle this...)

@hamishknight
Copy link
Contributor Author

@CodaFi You mean the lookup caches for all the nominal types? Or eagerly deserializing all the module's extension decls (thereby invalidating the lookup caches for the nominals being extended)? In either case IMO that seems unnecessarily expensive if we never need to do any lookups.

(I would have expected binding new extensions to already handle this...)

Right, it does, but that only happens when we load in the extensions. This patch ensures that we load in all the relevant extensions prior to consulting the lazily complete cache (thereby ensuring it's up-to-date).

@CodaFi
Copy link
Contributor

CodaFi commented Jun 15, 2020

Right. Let's take the

if (!disableAdditionalExtensionLoading)
  decl->prepareExtensions();

version then.

Call prepareExtensions to make sure we load in any
new extensions brought in by modules loaded
after-the-fact. This isn't an issue for normal
compilations as we load all the modules up-front
in import resolution, but clients such as the
LLDB REPL may load in modules later.

Resolves rdar://64040436.
@hamishknight hamishknight force-pushed the cached-my-last-rain-check branch from cdd7963 to 4b1ffa5 Compare June 15, 2020 19:16
@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#1338

@swift-ci please test

@hamishknight hamishknight merged commit f155ce8 into swiftlang:master Jun 15, 2020
@hamishknight hamishknight deleted the cached-my-last-rain-check branch June 15, 2020 22:02
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.

2 participants