From fe00dc74ea02a98733a8aa41c1f901b46aa0421b Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 13 Jul 2016 23:52:23 -0700 Subject: [PATCH] Get rid of _stdlib_didEnterMain Process arguments are now fetched per-platform --- include/swift/AST/KnownDecls.def | 1 - lib/Immediate/ImmediateImpl.h | 6 +++-- lib/SILGen/SILGen.cpp | 35 ++++++++-------------------- stdlib/public/core/CommandLine.swift | 20 ---------------- test/DebugInfo/top_level_code.swift | 4 ++-- test/IRGen/enum_derived.swift | 4 ++-- 6 files changed, 18 insertions(+), 52 deletions(-) diff --git a/include/swift/AST/KnownDecls.def b/include/swift/AST/KnownDecls.def index fdbf112381788..4b44c158b0e89 100644 --- a/include/swift/AST/KnownDecls.def +++ b/include/swift/AST/KnownDecls.def @@ -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") diff --git a/lib/Immediate/ImmediateImpl.h b/lib/Immediate/ImmediateImpl.h index 749e4ee6f9451..acb4d0aacf1a7 100644 --- a/lib/Immediate/ImmediateImpl.h +++ b/lib/Immediate/ImmediateImpl.h @@ -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 LinkLibraries, SearchPathOptions SearchPathOpts, diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 7ff1872ac7c00..86928dee1b795 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -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()) @@ -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()); @@ -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); } } diff --git a/stdlib/public/core/CommandLine.swift b/stdlib/public/core/CommandLine.swift index 4143bbe4a0c75..1002cec58ff76 100644 --- a/stdlib/public/core/CommandLine.swift +++ b/stdlib/public/core/CommandLine.swift @@ -47,23 +47,3 @@ public enum CommandLine { public static var arguments: [String] = (0..?> -) { - // 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 { - internal var _value: Wrapped - internal init(_ value: Wrapped) { self._value = value } -} - diff --git a/test/DebugInfo/top_level_code.swift b/test/DebugInfo/top_level_code.swift index 8b6d70202cb74..561db23b5e548 100644 --- a/test/DebugInfo/top_level_code.swift +++ b/test/DebugInfo/top_level_code.swift @@ -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 diff --git a/test/IRGen/enum_derived.swift b/test/IRGen/enum_derived.swift index 716a252266856..263184d32d693 100644 --- a/test/IRGen/enum_derived.swift +++ b/test/IRGen/enum_derived.swift @@ -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 : Int64 { case Up