-
Notifications
You must be signed in to change notification settings - Fork 197
[Target] Centralize creation of scratch SwiftASTContexts #1772
base: stable
Are you sure you want to change the base?
Conversation
@swift-ci please test |
friendly ping @JDevlieghere @dcci @adrian-prantl |
This makes sense to me. Not sure if @adrian-prantl, @JDevlieghere, or @dcci have any objections. |
There was a problem hiding this 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.
source/Target/Target.cpp
Outdated
@@ -2538,6 +2538,14 @@ SwiftASTContextReader Target::GetScratchSwiftASTContext( | |||
return SwiftASTContextReader(GetSwiftScratchContextLock(), swift_ast_ctx); | |||
} | |||
|
|||
SwiftASTContextReader Target::GetScratchSwiftASTContext(ValueObject &valobj, | |||
bool create_on_demand) { | |||
Status error; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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.
c091272
to
91e5f2f
Compare
@swift-ci please test |
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.