Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

[Target] Centralize creation of scratch SwiftASTContexts #1772

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from

Conversation

bulbazord
Copy link
Collaborator

I don't think it makes sense for ValueObject to know about SwiftASTContexts, so
we should centralize the creation logic into Target.

I know there are still references to SwiftASTContext in parts of ValueObject and its subclasses. I plan to try to factor those out sometime later.

@bulbazord bulbazord requested a review from adrian-prantl July 3, 2019 15:38
@bulbazord
Copy link
Collaborator Author

@swift-ci please test

@bulbazord
Copy link
Collaborator Author

friendly ping @JDevlieghere @dcci @adrian-prantl

@compnerd
Copy link
Collaborator

compnerd commented Jul 9, 2019

This makes sense to me. Not sure if @adrian-prantl, @JDevlieghere, or @dcci have any objections.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

I'm not an expert on the functionality, but I'd prefer for us to improve error handling while we're around.

@@ -2538,6 +2538,14 @@ SwiftASTContextReader Target::GetScratchSwiftASTContext(
return SwiftASTContextReader(GetSwiftScratchContextLock(), swift_ast_ctx);
}

SwiftASTContextReader Target::GetScratchSwiftASTContext(ValueObject &valobj,
bool create_on_demand) {
Status error;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this error getting swallowed.

Status error;
ExecutionContext ctx = valobj.GetExecutionContextRef().Lock(false);
auto *exe_scope = ctx.GetBestExecutionContextScope();
return GetScratchSwiftASTContext(error, *exe_scope);
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this return an llvm::Expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I can do that :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay so I just looked into it. Looks like We always return a SwiftASTContextReader no matter what, so returning an llvm::Expected doesn't make much sense here. What I did find is that GetScratchSwiftASTContext will sometimes fail to build a scratch SwiftASTContext and instead return the project-wide scratch SwiftASTContext. Even if we fail to build a SwiftASTContext, we still return a SwiftASTContextReader.

Copy link
Member

Choose a reason for hiding this comment

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

I have no strong preferences, so I'm happy with this once Jonas feels his comments have been addressed.
Maybe longer term we can enforce that the SwiftASTContextReader returned is always valid [and if it's not, assert], given we expect it in such state..

Copy link
Member

Choose a reason for hiding this comment

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

Do we ever need to differentiate between the two? This code is saying that the error doesn't matter. Is that true for this function, or is that true always? In the latter case, maybe we should remove the Status as the first argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the looks of it, Target::GetScratchSwiftASTContext will return a Status and the callsites generally use them. It looks like error handling is just not taken into account with the ValueObject version. So even though it's true just for this function, I think that we can probably do a better job and improve error handling here by making the ValueObject version take a Status and then have the clients actually use that Status for error handling.

@bulbazord
Copy link
Collaborator Author

@JDevlieghere Mind taking another look when you get the chance?

I don't think it makes sense for ValueObject to know about SwiftASTContexts, so
we should centralize the creation logic into Target.
@bulbazord bulbazord force-pushed the target_experiment branch from c091272 to 91e5f2f Compare July 17, 2019 22:00
@bulbazord
Copy link
Collaborator Author

@swift-ci please test

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants