Skip to content

Commit 740cb36

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 722e7d6 + d86fec9 commit 740cb36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+288
-159
lines changed

CMakeLists.txt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,6 @@ include(CMakePushCheckState)
499499

500500
print_versions()
501501

502-
include(SwiftSharedCMakeConfig)
503-
504-
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
505-
# functionality.
506-
# Support building Swift as a standalone project, using LLVM as an
507-
# external library.
508-
if(SWIFT_BUILT_STANDALONE)
509-
swift_common_standalone_build_config(SWIFT)
510-
else()
511-
swift_common_unified_build_config(SWIFT)
512-
endif()
513-
514502
include(SwiftComponents)
515503
include(SwiftHandleGybSources)
516504
include(SwiftSetIfArchBitness)
@@ -539,6 +527,16 @@ if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
539527
OUTPUT_STRIP_TRAILING_WHITESPACE)
540528
endif()
541529

530+
include(SwiftSharedCMakeConfig)
531+
532+
# Support building Swift as a standalone project, using LLVM as an
533+
# external library.
534+
if(SWIFT_BUILT_STANDALONE)
535+
swift_common_standalone_build_config(SWIFT)
536+
else()
537+
swift_common_unified_build_config(SWIFT)
538+
endif()
539+
542540
get_filename_component(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
543541
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
544542
set(SWIFT_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -1053,7 +1051,6 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
10531051
else()
10541052
set(SOURCEKIT_RUNTIME_DIR lib)
10551053
endif()
1056-
add_dependencies(sourcekit-inproc BlocksRuntime dispatch)
10571054
swift_install_in_component(FILES
10581055
$<TARGET_FILE:dispatch>
10591056
$<TARGET_FILE:BlocksRuntime>

apinotes/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ add_custom_target("copy_apinotes" ALL
2626
COMMENT "Copying API notes to ${output_dir}"
2727
SOURCES "${sources}")
2828

29-
add_dependencies(compiler copy_apinotes)
3029
swift_install_in_component(DIRECTORY "${output_dir}"
3130
DESTINATION "lib/swift/"
3231
COMPONENT compiler)

cmake/modules/AddSwift.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,6 @@ function(add_swift_host_library name)
15061506
INSTALL_IN_COMPONENT "dev"
15071507
)
15081508

1509-
add_dependencies(dev ${name})
15101509
if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
15111510
swift_install_in_component(TARGETS ${name}
15121511
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT dev
@@ -2118,7 +2117,6 @@ function(add_swift_target_library name)
21182117
endif()
21192118

21202119
if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
2121-
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH})
21222120
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
21232121
RUNTIME
21242122
DESTINATION "bin"
@@ -2131,9 +2129,6 @@ function(add_swift_target_library name)
21312129
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
21322130
PERMISSIONS ${file_permissions})
21332131
else()
2134-
# NOTE: ${UNIVERSAL_LIBRARY_NAME} is the output associated with the target
2135-
# ${lipo_target}
2136-
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target})
21372132
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
21382133
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
21392134
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
@@ -2144,7 +2139,6 @@ function(add_swift_target_library name)
21442139
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
21452140
if(TARGET ${name}-windows-${arch}_IMPLIB)
21462141
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
2147-
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${arch}_IMPLIB)
21482142
swift_install_in_component(FILES ${import_library}
21492143
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
21502144
COMPONENT ${SWIFTLIB_INSTALL_IN_COMPONENT}
@@ -2211,7 +2205,6 @@ function(add_swift_target_library name)
22112205
OUTPUT
22122206
"${UNIVERSAL_LIBRARY_NAME}"
22132207
${THIN_INPUT_TARGETS_STATIC})
2214-
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target_static})
22152208
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
22162209
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${install_subdir}/${resource_dir_sdk_subdir}"
22172210
PERMISSIONS
@@ -2413,7 +2406,6 @@ function(add_swift_host_tool executable)
24132406
ARCHITECTURE ${SWIFT_HOST_VARIANT_ARCH}
24142407
${ASHT_UNPARSED_ARGUMENTS})
24152408

2416-
add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
24172409
swift_install_in_component(TARGETS ${executable}
24182410
RUNTIME
24192411
DESTINATION bin

cmake/modules/SwiftComponents.cmake

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,11 @@ macro(swift_configure_components)
9292
"A semicolon-separated list of components to install from the set ${_SWIFT_DEFINED_COMPONENTS}")
9393

9494
foreach(component ${_SWIFT_DEFINED_COMPONENTS})
95-
add_custom_target(${component})
96-
add_llvm_install_targets(install-${component}
97-
DEPENDS ${component}
98-
COMPONENT ${component})
99-
10095
string(TOUPPER "${component}" var_name_piece)
10196
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
10297
set(SWIFT_INSTALL_${var_name_piece} FALSE)
10398
endforeach()
10499

105-
# NOTE: never_install is a dummy component to indicate something should not
106-
# be installed. We explicitly do not add an install target for this.
107-
add_custom_target(never_install)
108-
109-
add_custom_target(swift-components)
110-
add_custom_target(install-swift-components)
111-
112100
foreach(component ${SWIFT_INSTALL_COMPONENTS})
113101
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
114102
message(FATAL_ERROR "unknown install component: ${component}")
@@ -118,8 +106,6 @@ macro(swift_configure_components)
118106
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
119107
if(NOT SWIFT_INSTALL_EXCLUDE_${var_name_piece})
120108
set(SWIFT_INSTALL_${var_name_piece} TRUE)
121-
add_dependencies(swift-components ${component})
122-
add_dependencies(install-swift-components install-${component})
123109
endif()
124110
endforeach()
125111
endmacro()
@@ -188,6 +174,5 @@ function(swift_install_symlink_component component)
188174
MESSAGE "LLVMInstallSymlink script must be available.")
189175

190176
install(SCRIPT ${INSTALL_SYMLINK}
191-
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})"
192-
COMPONENT ${component})
177+
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})")
193178
endfunction()

cmake/modules/SwiftManpage.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function(manpage)
2727
"${CMAKE_CURRENT_BINARY_DIR}/${MP_MAN_FILE_BASENAME}.${MP_MAN_SECTION}")
2828

2929
add_custom_command_target(
30-
manpage_target
30+
unused_var
3131
COMMAND
3232
"${POD2MAN}" "--section" "${MP_MAN_SECTION}"
3333
"--center" "${MP_PAGE_HEADER}" "--release=\"swift ${SWIFT_VERSION}\""
@@ -38,7 +38,6 @@ function(manpage)
3838
DEPENDS "${MP_SOURCE}"
3939
ALL)
4040

41-
add_dependencies(${MP_INSTALL_IN_COMPONENT} ${manpage_target})
4241
swift_install_in_component(FILES "${output_file_name}"
4342
DESTINATION "share/man/man${MP_MAN_SECTION}"
4443
COMPONENT "${MP_INSTALL_IN_COMPONENT}")

docs/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ if (DOXYGEN_FOUND)
6868
add_dependencies(doxygen doxygen-swift)
6969
endif()
7070

71-
add_dependencies(dev doxygen-swift)
7271
swift_install_in_component(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
7372
DESTINATION "docs/html"
7473
COMPONENT dev)

include/swift/SIL/SILFunction.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "llvm/ADT/StringMap.h"
2929

3030
/// The symbol name used for the program entry point function.
31-
/// FIXME: Hardcoding this is lame.
3231
#define SWIFT_ENTRY_POINT_FUNCTION "main"
3332

3433
namespace swift {
@@ -57,6 +56,10 @@ enum IsDynamicallyReplaceable_t {
5756
IsNotDynamic,
5857
IsDynamic
5958
};
59+
enum IsExactSelfClass_t {
60+
IsNotExactSelfClass,
61+
IsExactSelfClass,
62+
};
6063

6164
class SILSpecializeAttr final {
6265
friend SILFunction;
@@ -200,6 +203,10 @@ class SILFunction
200203

201204
/// Whether the implementation can be dynamically replaced.
202205
unsigned IsDynamicReplaceable : 1;
206+
207+
/// If true, this indicates that a class method implementation will always be
208+
/// invoked with a `self` argument of the exact base class type.
209+
unsigned ExactSelfClass : 1;
203210

204211
/// If != OptimizationMode::NotSet, the optimization mode specified with an
205212
/// function attribute.
@@ -294,14 +301,16 @@ class SILFunction
294301
SubclassScope classSubclassScope, Inline_t inlineStrategy,
295302
EffectsKind E, SILFunction *insertBefore,
296303
const SILDebugScope *debugScope,
297-
IsDynamicallyReplaceable_t isDynamic);
304+
IsDynamicallyReplaceable_t isDynamic,
305+
IsExactSelfClass_t isExactSelfClass);
298306

299307
static SILFunction *
300308
create(SILModule &M, SILLinkage linkage, StringRef name,
301309
CanSILFunctionType loweredType, GenericEnvironment *genericEnv,
302310
Optional<SILLocation> loc, IsBare_t isBareSILFunction,
303311
IsTransparent_t isTrans, IsSerialized_t isSerialized,
304312
ProfileCounter entryCount, IsDynamicallyReplaceable_t isDynamic,
313+
IsExactSelfClass_t isExactSelfClass,
305314
IsThunk_t isThunk = IsNotThunk,
306315
SubclassScope classSubclassScope = SubclassScope::NotApplicable,
307316
Inline_t inlineStrategy = InlineDefault,
@@ -587,14 +596,21 @@ class SILFunction
587596
IsWeakLinked = value;
588597
}
589598

590-
/// Returs whether this function implementation can be dynamically replaced.
599+
/// Returns whether this function implementation can be dynamically replaced.
591600
IsDynamicallyReplaceable_t isDynamicallyReplaceable() const {
592601
return IsDynamicallyReplaceable_t(IsDynamicReplaceable);
593602
}
594603
void setIsDynamic(IsDynamicallyReplaceable_t value = IsDynamic) {
595604
IsDynamicReplaceable = value;
596605
assert(!Transparent || !IsDynamicReplaceable);
597606
}
607+
608+
IsExactSelfClass_t isExactSelfClass() const {
609+
return IsExactSelfClass_t(ExactSelfClass);
610+
}
611+
void setIsExactSelfClass(IsExactSelfClass_t t) {
612+
ExactSelfClass = t;
613+
}
598614

599615
/// Get the DeclContext of this function. (Debug info only).
600616
DeclContext *getDeclContext() const {

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 506; // transparent accessor bit
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 507; // exact_self_class sil attr
5656

5757
using DeclIDField = BCFixed<31>;
5858

lib/Driver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@ if(SWIFT_BUILD_STATIC_STDLIB)
6262
endif()
6363
endforeach()
6464
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})
65-
add_dependencies(stdlib swift_static_lnk_args)
6665
endif()

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ llvm::Value *IRGenFunction::getLocalSelfMetadata() {
17181718
break;
17191719
case ObjectReference:
17201720
LocalSelf = emitDynamicTypeOfOpaqueHeapObject(*this, LocalSelf,
1721-
MetatypeRepresentation::Thick);
1721+
MetatypeRepresentation::Thick);
17221722
SelfKind = SwiftMetatype;
17231723
break;
17241724
}

lib/IRGen/GenType.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2255,10 +2255,14 @@ unsigned IRGenModule::getBuiltinIntegerWidth(BuiltinIntegerWidth w) {
22552255
llvm_unreachable("impossible width value");
22562256
}
22572257

2258-
void IRGenFunction::setLocalSelfMetadata(llvm::Value *value,
2258+
void IRGenFunction::setLocalSelfMetadata(CanType exactSelfClass,
2259+
llvm::Value *value,
22592260
IRGenFunction::LocalSelfKind kind) {
22602261
assert(!LocalSelf && "already have local self metadata");
22612262
LocalSelf = value;
2263+
assert((!exactSelfClass || exactSelfClass->getClassOrBoundGenericClass())
2264+
&& "self type not a class?");
2265+
ExactSelfType = exactSelfClass;
22622266
SelfKind = kind;
22632267
}
22642268

lib/IRGen/IRGenFunction.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ class IRGenFunction {
644644
};
645645

646646
llvm::Value *getLocalSelfMetadata();
647-
void setLocalSelfMetadata(llvm::Value *value, LocalSelfKind kind);
647+
void setLocalSelfMetadata(CanType selfBaseTy,
648+
llvm::Value *value, LocalSelfKind kind);
648649

649650
private:
650651
LocalTypeDataCache &getOrCreateLocalTypeData();
@@ -660,7 +661,8 @@ class IRGenFunction {
660661

661662
/// The value that satisfies metadata lookups for dynamic Self.
662663
llvm::Value *LocalSelf = nullptr;
663-
664+
/// If set, the dynamic Self type is assumed to be equivalent to this exact class.
665+
CanType ExactSelfType;
664666
LocalSelfKind SelfKind;
665667
};
666668

lib/IRGen/IRGenSIL.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,23 +1584,38 @@ static void emitLocalSelfMetadata(IRGenSILFunction &IGF) {
15841584
return;
15851585

15861586
const SILArgument *selfArg = IGF.CurSILFn->getSelfMetadataArgument();
1587+
auto selfTy = selfArg->getType().getASTType();
15871588
CanMetatypeType metaTy =
1588-
dyn_cast<MetatypeType>(selfArg->getType().getASTType());
1589+
dyn_cast<MetatypeType>(selfTy);
15891590
IRGenFunction::LocalSelfKind selfKind;
15901591
if (!metaTy)
15911592
selfKind = IRGenFunction::ObjectReference;
1592-
else switch (metaTy->getRepresentation()) {
1593-
case MetatypeRepresentation::Thin:
1594-
llvm_unreachable("class metatypes are never thin");
1595-
case MetatypeRepresentation::Thick:
1596-
selfKind = IRGenFunction::SwiftMetatype;
1597-
break;
1598-
case MetatypeRepresentation::ObjC:
1599-
selfKind = IRGenFunction::ObjCMetatype;
1600-
break;
1593+
else {
1594+
selfTy = metaTy.getInstanceType();
1595+
switch (metaTy->getRepresentation()) {
1596+
case MetatypeRepresentation::Thin:
1597+
llvm_unreachable("class metatypes are never thin");
1598+
case MetatypeRepresentation::Thick:
1599+
selfKind = IRGenFunction::SwiftMetatype;
1600+
break;
1601+
case MetatypeRepresentation::ObjC:
1602+
selfKind = IRGenFunction::ObjCMetatype;
1603+
break;
1604+
}
16011605
}
16021606
llvm::Value *value = IGF.getLoweredExplosion(selfArg).claimNext();
1603-
IGF.setLocalSelfMetadata(value, selfKind);
1607+
if (auto dynSelfTy = dyn_cast<DynamicSelfType>(selfTy))
1608+
selfTy = dynSelfTy.getSelfType();
1609+
1610+
// Specify the exact Self type if we know it, either because the class
1611+
// is final, or because the function we're emitting is a method with the
1612+
// [exact_self_class] attribute set on it during the SIL pipeline.
1613+
CanType exactSelfTy;
1614+
if (selfTy->getClassOrBoundGenericClass()->isFinal()
1615+
|| IGF.CurSILFn->isExactSelfClass())
1616+
exactSelfTy = selfTy;
1617+
1618+
IGF.setLocalSelfMetadata(exactSelfTy, value, selfKind);
16041619
}
16051620

16061621
/// Emit the definition for the given SIL constant.

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,12 @@ IRGenFunction::emitTypeMetadataRef(CanType type,
23782378
// Look through any opaque types we're allowed to.
23792379
type = IGM.substOpaqueTypesWithUnderlyingTypes(type);
23802380

2381+
// If we're asking for the metadata of the type that dynamic Self is known
2382+
// to be equal to, we can just use the self metadata.
2383+
if (ExactSelfType == type) {
2384+
return MetadataResponse::forComplete(getLocalSelfMetadata());
2385+
}
2386+
23812387
if (type->hasArchetype() ||
23822388
isTypeMetadataAccessTrivial(IGM, type)) {
23832389
// FIXME: propagate metadata request!

0 commit comments

Comments
 (0)