Skip to content

[Frontend] Load standard libarary in CompilerInstance::setup #40107

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 2 commits into from
Dec 14, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Nov 9, 2021

Instead of checking that the stdlib can be loaded in a variety of places, check it when setting up the compiler instance. This required a couple more checks to avoid loading the stdlib in cases where it’s not needed.

To be able to differentiate stdlib loading failures from other setup errors, make CompilerInstance::setup return an error message on failure via an inout parameter. Consume that error on the call side, replacing a previous, more generic error message, adding error handling where appropriate or ignoring the error message, depending on the context.


Was discussed in #39631 (comment)

@ahoppen ahoppen requested a review from hamishknight November 9, 2021 15:03
@ahoppen
Copy link
Member Author

ahoppen commented Nov 9, 2021

@swift-ci Please smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! I'm not too familiar with a couple of the places this affects though, so I've tagged a couple of folks to take a look

@ahoppen ahoppen force-pushed the pr/load-stdlib-in-setup branch 3 times, most recently from a42c090 to f9e0aae Compare November 11, 2021 12:32
@ahoppen
Copy link
Member Author

ahoppen commented Nov 11, 2021

@swift-ci Please smoke test

Comment on lines +314 to +318
case FrontendOptions::ActionType::ScanDependencies:
requestedAction = Opts.RequestedAction;
break;
Copy link
Contributor

@hamishknight hamishknight Nov 16, 2021

Choose a reason for hiding this comment

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

@nkcsgexi @artemcm Does this look good to you?

Would you mind also double checking that there aren't other callers of CompilerInstance::setup where we may need to change the requested action to avoid loading the stdlib? In particular I'm not too sure what frontend arguments are being fed for the other dependency scanning call-sites, are they guaranteed to use the dependency scanning action?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine to me.
I also fully expect all dependency scanning call-sites to also have FrontendOptions::ActionType::ScanDependencies.

Comment on lines +314 to +318
case FrontendOptions::ActionType::ScanDependencies:
requestedAction = Opts.RequestedAction;
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine to me.
I also fully expect all dependency scanning call-sites to also have FrontendOptions::ActionType::ScanDependencies.

@ahoppen ahoppen force-pushed the pr/load-stdlib-in-setup branch from f9e0aae to 599b32e Compare November 17, 2021 10:41
@ahoppen
Copy link
Member Author

ahoppen commented Nov 23, 2021

@swift-ci Please smoke test

Instead of checking that the stdlib can be loaded in a variety of places, check it when setting up the compiler instance. This required a couple more checks to avoid loading the stdlib in cases where it’s not needed.

To be able to differentiate stdlib loading failures from other setup errors, make `CompilerInstance::setup` return an error message on failure via an inout parameter. Consume that error on the call side, replacing a previous, more generic error message, adding error handling where appropriate or ignoring the error message, depending on the context.
…piler invocation

Explicitly specify the frontend action to make sure we aren’t loading thes stdlib if the performed action is syntactic only.
@ahoppen ahoppen force-pushed the pr/load-stdlib-in-setup branch from 599b32e to 22f67e8 Compare December 13, 2021 14:34
@ahoppen
Copy link
Member Author

ahoppen commented Dec 13, 2021

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 4fc9d01 into swiftlang:main Dec 14, 2021
@ahoppen ahoppen deleted the pr/load-stdlib-in-setup branch December 14, 2021 12:45
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