Skip to content

Conversation

@adrian-prantl
Copy link

This patch moves the bulk of SwiftLanguageRuntime into a private
implementation class that is only initialized after libSwiftCore has
been loaded. This delay is necessary because SwiftLanguageRuntime
communicates with the in-process Swift language runtime via global
symbols and can't be properly initialized before the runtime was
loaded. Before the runtime was loaded all queries go to the
SwiftLanguageRuntimeStub, which prints an error message for most
queries.

In addition this patch re-enables the expression evaluator loading
libSwiftCore manually. This was previously disabled to prevent
problems with statically linked runtimes on Darwin, howver, since ABI
stabiklity statically linking the runtime is no longer an option on
Darwin.

rdar://problem/58352018
rdar://problem/58117895

Copy link
Author

Choose a reason for hiding this comment

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

This may look like a regression at first glance, but this avoids an extra copy of the string, since we need to pass it to a Swift API that takes a const char *.

Copy link

Choose a reason for hiding this comment

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

I'm not sure I follow. A few questions:

  • Should SwiftLanguageRuntime::IsSwiftMangledName() take a StringRef?
  • The comment in cstring_is_mangled implies that ConstString::GetStringRef() doesn't always return a null-terminated string. Is this correct?

Copy link
Author

@adrian-prantl adrian-prantl Jan 8, 2020

Choose a reason for hiding this comment

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

SwiftLanguageRuntime::IsSwiftMangledName() calls into a Swift API that takes a const char *; so changing that to a StringRef would incur an extra copy to ensure the NUL-terminator. ConstStrings are — to my knowledge — always NUL-terminated.

Copy link

Choose a reason for hiding this comment

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

So I don't understand what calling AsCString() instead of GetStringRef() fixes. Given cstring_is_mangled() takes a StringRef, what this achieves is creating a temporary one which will need to strlen the passed char*. What am I missing?

Copy link
Author

Choose a reason for hiding this comment

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

Gotcha. I was confused.

@adrian-prantl
Copy link
Author

My apologies for the enormous patch.

@adrian-prantl
Copy link
Author

This patch also fixes the last test failure on the branch.

Copy link
Member

@dcci dcci left a comment

Choose a reason for hiding this comment

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

I need a little time to review this patch properly -- I think I'll get to it by the end of today.
I have a meta comment, so I'll drop it here before I forget. One of the main nuisances of the current model is the inability of detecting whether stdlib failed to load and expressions keep going and fail in fairly non-obvious way.

My understanding is that this is kind of the first step towards a world where if stdlib isn't found and loaded correctly, expressions just can't be run. Is this correct?

Copy link
Member

@dcci dcci left a comment

Choose a reason for hiding this comment

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

Can you commit the NFC/cosmetic changes first -- so we can review the meat of this PR better? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I think there are lots of changes that are just cosmetics, and can be separated. Like this.

…sent.

This patch moves the bulk of SwiftLanguageRuntime into a private
implementation class that is only initialized after libSwiftCore has
been loaded. This delay is necessary because SwiftLanguageRuntime
communicates with the in-process Swift language runtime via global
symbols and can't be properly initialized before the runtime was
loaded. Before the runtime was loaded all queries go to the
SwiftLanguageRuntimeStub, which prints an error message for most
queries.

In addition this patch re-enables the expression evaluator loading
libSwiftCore manually. This was previously disabled to prevent
problems with statically linked runtimes on Darwin, howver, since ABI
stabiklity statically linking the runtime is no longer an option on
Darwin.

<rdar://problem/58352018>
<rdar://problem/58117895>
@adrian-prantl
Copy link
Author

I need a little time to review this patch properly -- I think I'll get to it by the end of today.
I have a meta comment, so I'll drop it here before I forget. One of the main nuisances of the current model is the inability of detecting whether stdlib failed to load and expressions keep going and fail in fairly non-obvious way.

My understanding is that this is kind of the first step towards a world where if stdlib isn't found and loaded correctly, expressions just can't be run. Is this correct?

No, when the stdlib isn't loaded, after this patch, SwiftUserExpression will dlopen libSwiftCore itself.

@adrian-prantl
Copy link
Author

Can you commit the NFC/cosmetic changes first -- so we can review the meat of this PR better? Thanks!

The bulk of the patch is moving around function bodies into different classes, so this isn't going to work quite as nicely as we'd hope.

@dcci
Copy link
Member

dcci commented Jan 8, 2020

I need a little time to review this patch properly -- I think I'll get to it by the end of today.
I have a meta comment, so I'll drop it here before I forget. One of the main nuisances of the current model is the inability of detecting whether stdlib failed to load and expressions keep going and fail in fairly non-obvious way.
My understanding is that this is kind of the first step towards a world where if stdlib isn't found and loaded correctly, expressions just can't be run. Is this correct?

No, when the stdlib isn't loaded, after this patch, SwiftUserExpression will dlopen libSwiftCore itself.

I guess my question is: "what happens if SwiftUserExpression fails to load libSwiftcore?

@adrian-prantl
Copy link
Author

I guess my question is: "what happens if SwiftUserExpression fails to load libSwiftcore?

Then SwiftLanguageRuntimeImpl will not be loaded (since no libswiftCore.dylib is in the loaded images) and all queries go to the stub instead.

@adrian-prantl
Copy link
Author

... which will log an error. Note that this is a highly unlikely scenario. You could run into it on Linux by doing expr -l Swift -- 1 on a system without Swift installed.

@adrian-prantl adrian-prantl changed the base branch from swift/master-next to swift/master-rebranch January 9, 2020 01:07
Copy link
Member

@dcci dcci left a comment

Choose a reason for hiding this comment

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

LGTM.

@adrian-prantl adrian-prantl merged commit 64f1104 into swiftlang:swift/master-rebranch Jan 9, 2020
kastiglione added a commit that referenced this pull request May 6, 2021
The swift override of `IsSymbolARuntimeThunk` was unintentionally removed in #536. This restores it.

rdar://65681037
kastiglione added a commit that referenced this pull request May 6, 2021
The swift override of `IsSymbolARuntimeThunk` was unintentionally removed in #536. This restores it.

rdar://65681037

(cherry picked from #2917)
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