-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] In -assert-config Debug, print errors in assertions, preconditions, fatalErrors #72817
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
[embedded] In -assert-config Debug, print errors in assertions, preconditions, fatalErrors #72817
Conversation
PR is missing tests, will add them once we get agreement that this is the right approach :) |
lib/SIL/IR/Linker.cpp
Outdated
@@ -102,7 +102,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F, | |||
bool setToSerializable) { | |||
SILLinkage linkage = F->getLinkage(); | |||
assert((!setToSerializable || F->hasValidLinkageForFragileRef() || | |||
hasSharedVisibility(linkage)) && | |||
hasSharedVisibility(linkage) || Mod.getOptions().EmbeddedSwift) && |
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.
@eeckstein do you have guidance on whether relaxing this assert is reasonable, or if there's a better way to solve the following problem?
Basically the situation is: The stdlib has an @_extern(c) func putchar
(without a body), which gets serialized into the stdlib. A user module also has a @_extern(c) func putchar
(without a body). This then triggers this assert when we indirectly end up deserializing this forward declaration from the stdlib.
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.
Hm, can this also happen in regular swift?
Is it possible to narrow down the case, e.g. exclude C function decls?
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.
This is the minimal reproducer:
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
// REQUIRES: swift_in_compiler
// REQUIRES: OS=macosx || OS=linux-gnu
// BEGIN MyModule.swift
@_extern(c)
func some_c_api()
@_transparent
public func publicFuncInAModule() {
internalFuncInAModule()
}
@usableFromInline
internal func internalFuncInAModule() {
some_c_api()
}
// BEGIN Main.swift
import MyModule
@_extern(c)
func some_c_api()
some_c_api()
publicFuncInAModule()
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.
As discussed offline, it's only happening in embedded swift. It's fine to keep it as is. Just add your explanation as a short comment
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.
See my comment about the assert. Otherwise LGTM
lib/SIL/IR/Linker.cpp
Outdated
@@ -102,7 +102,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F, | |||
bool setToSerializable) { | |||
SILLinkage linkage = F->getLinkage(); | |||
assert((!setToSerializable || F->hasValidLinkageForFragileRef() || | |||
hasSharedVisibility(linkage)) && | |||
hasSharedVisibility(linkage) || Mod.getOptions().EmbeddedSwift) && |
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.
Hm, can this also happen in regular swift?
Is it possible to narrow down the case, e.g. exclude C function decls?
1100ab8
to
34dc983
Compare
@swift-ci please test |
df7ca9e
to
9fea230
Compare
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.
lgtm!
@swift-ci please test |
9fea230
to
0c73c57
Compare
…nditions, fatalErrors
…st to allow external forward-declarations even in regular Swift, add tests
…uction builds (-Onone or -assert-config Debug)
…itionFailure in embedded Swift
0c73c57
to
67f3d34
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
This PR aims to improve how preconditions and fatalErrors are compiled in Embedded Swift:
-assert-config Debug
: