Skip to content

[Stdlib][ABI] Resolve ABI FIXME #25 #6246

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 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/AST/KnownDecls.def
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ FUNC_DECL(BridgeAnyObjectToAny,

FUNC_DECL(ConvertToAnyHashable, "_convertToAnyHashable")

FUNC_DECL(DidEnterMain, "_stdlib_didEnterMain")
FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional")

FUNC_DECL(GetErrorEmbeddedNSError, "_stdlib_getErrorEmbeddedNSError")
Expand Down
6 changes: 4 additions & 2 deletions lib/Immediate/ImmediateImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ namespace swift {

namespace immediate {

// Returns a handle to the runtime suitable for other 'dlsym' or 'dlclose'
// calls or 'NULL' if an error occurred.
/// Returns a handle to the runtime suitable for other \c dlsym or \c dlclose
/// calls or \c null if an error occurred.
///
/// \param runtimeLibPath Path to search for compiler-relative stdlib dylibs.
void *loadSwiftRuntime(StringRef runtimeLibPath);
bool tryLoadLibraries(ArrayRef<LinkLibrary> LinkLibraries,
SearchPathOptions SearchPathOpts,
Expand Down
35 changes: 10 additions & 25 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,29 +1223,6 @@ void SILGenModule::visitTopLevelCodeDecl(TopLevelCodeDecl *td) {
}
}

static void emitTopLevelProlog(SILGenFunction &gen, SILLocation loc) {
assert(gen.B.getInsertionBB()->getIterator() == gen.F.begin()
&& "not at entry point?!");

SILBasicBlock *entry = gen.B.getInsertionBB();
// Create the argc and argv arguments.
auto &C = gen.getASTContext();
auto FnTy = gen.F.getLoweredFunctionType();
auto *argc = entry->createArgument(FnTy->getParameters()[0].getSILType());
auto *argv = entry->createArgument(FnTy->getParameters()[1].getSILType());

// If the standard library provides a _stdlib_didEnterMain intrinsic, call it
// first thing.
if (auto didEnterMain = C.getDidEnterMain(nullptr)) {
ManagedValue params[] = {
ManagedValue::forUnmanaged(argc),
ManagedValue::forUnmanaged(argv),
};
(void) gen.emitApplyOfLibraryIntrinsic(loc, didEnterMain, {}, params,
SGFContext());
}
}

void SILGenModule::useConformance(ProtocolConformanceRef conformanceRef) {
// We don't need to emit dependent conformances.
if (conformanceRef.isAbstract())
Expand Down Expand Up @@ -1308,9 +1285,13 @@ class SourceFileScope {
sgm.TopLevelSGF->prepareRethrowEpilog(
CleanupLocation::getModuleCleanupLocation());

// Create the argc and argv arguments.
auto PrologueLoc = RegularLocation::getModuleLocation();
PrologueLoc.markAsPrologue();
emitTopLevelProlog(*sgm.TopLevelSGF, PrologueLoc);
auto entry = sgm.TopLevelSGF->B.getInsertionBB();
auto FnTy = sgm.TopLevelSGF->F.getLoweredFunctionType();
entry->createArgument(FnTy->getParameters()[0].getSILType());
entry->createArgument(FnTy->getParameters()[1].getSILType());

scope.emplace(sgm.TopLevelSGF->Cleanups,
CleanupLocation::getModuleCleanupLocation());
Expand Down Expand Up @@ -1409,8 +1390,12 @@ class SourceFileScope {
// Assign a debug scope pointing into the void to the top level function.
toplevel->setDebugScope(new (sgm.M) SILDebugScope(TopLevelLoc, toplevel));

// Create the argc and argv arguments.
SILGenFunction gen(sgm, *toplevel);
emitTopLevelProlog(gen, mainClass);
auto entry = gen.B.getInsertionBB();
auto FnTy = gen.F.getLoweredFunctionType();
entry->createArgument(FnTy->getParameters()[0].getSILType());
entry->createArgument(FnTy->getParameters()[1].getSILType());
gen.emitArtificialTopLevel(mainClass);
}
}
Expand Down
20 changes: 0 additions & 20 deletions stdlib/public/core/CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,3 @@ public enum CommandLine {
public static var arguments: [String]
= (0..<Int(argc)).map { String(cString: _unsafeArgv[$0]!) }
}

// FIXME(ABI)#25 : Remove this and the entrypoints in SILGen.
// rdar://problem/19696522
@_transparent
public // COMPILER_INTRINSIC
func _stdlib_didEnterMain(
argc: Int32, argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>
) {
// Initialize the CommandLine.argc and CommandLine.unsafeArgv variables with the
// values that were passed in to main.
CommandLine._argc = Int32(argc)
CommandLine._unsafeArgv = argv
}

// FIXME: Move this to HashedCollections.swift.gyb
internal class _Box<Wrapped> {
internal var _value: Wrapped
internal init(_ value: Wrapped) { self._value = value }
}

4 changes: 2 additions & 2 deletions test/DebugInfo/top_level_code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ markUsed(a+b)
// CHECK: _main:
// Verify that the top-level function (main) begins at line 0 and then
// proceeds to line 6.
// CHECK: .loc {{[0-9]}} 0 {{[0-9]}} prologue_end
// CHECK: .loc {{[0-9]}} 0 {{[0-9]}}
// CHECK-NOT: .loc
// CHECK: .loc {{[0-9]}} 6 {{[0-9]}}
// CHECK: .loc {{[0-9]}} 6 {{[0-9]}} prologue_end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adrian-prantl This change seems sketchy to me.

Copy link
Member

Choose a reason for hiding this comment

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

Interestingly enough, this is something that I was recently looking at. Something has changed and when building swift against upstream-with-swift on clang/LLVM, it seems that the prolgue_end marker is no longer emitted. The MF does see the FrameSetup markers on the prologue instructions, but when the line record is constructued, we ignore the FrameSetup MIFlag and just drop the prologue tracking on the floor.

Also, it seems that for some reason this test is marked as XFAIL on Linux. Why is that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Judging from the version control history, this testcase was XFAILed some time during the Linux bringup and hasn't been looked at since.

@compnerd: could you file bugs for both of these issues and CC/assign it to me?

4 changes: 2 additions & 2 deletions test/IRGen/enum_derived.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extension def_enum.TrafficLight : Error {}

extension def_enum.Term : Error {}

// CHECK-NORMAL-LABEL: define hidden i64 @_TFO12enum_derived7Phantomg8rawValueVs5Int64(i1, %swift.type* nocapture readnone %T) local_unnamed_addr #1
// CHECK-TESTABLE-LABEL: define{{( protected)?}} i64 @_TFO12enum_derived7Phantomg8rawValueVs5Int64(i1, %swift.type* nocapture readnone %T) #1
// CHECK-NORMAL-LABEL: define hidden i64 @_TFO12enum_derived7Phantomg8rawValueVs5Int64(i1, %swift.type* nocapture readnone %T) local_unnamed_addr #0
// CHECK-TESTABLE-LABEL: define{{( protected)?}} i64 @_TFO12enum_derived7Phantomg8rawValueVs5Int64(i1, %swift.type* nocapture readnone %T) #0

enum Phantom<T> : Int64 {
case Up
Expand Down