Skip to content

Commit 7739252

Browse files
committed
---
yaml --- r: 345287 b: refs/heads/master c: 7f35914 h: refs/heads/master i: 345285: 32d0fc2 345283: b68ed0a 345279: 959748e
1 parent 98c56db commit 7739252

File tree

11 files changed

+214
-46
lines changed

11 files changed

+214
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bc236ff128ad62d314c40396c99c096e2ce8a7d3
2+
refs/heads/master: 7f359140d65264130e8ad34e16a505f121ba840e
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,14 @@ function(swift_icu_variables_set sdk arch result)
860860
endif()
861861
endfunction()
862862

863-
# ICU is provided through CoreFoundation on Darwin. On other hosts, assume that
864-
# we are compiling for the build as the host. In such a case, if the ICU
863+
# ICU is provided through CoreFoundation on Darwin. On other hosts, if the ICU
865864
# unicode and i18n include and library paths are not defined, perform a standard
866865
# package lookup. Otherwise, rely on the paths specified by the user. These
867866
# need to be defined when cross-compiling.
868867
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
869868
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
870-
swift_icu_variables_set("${SWIFT_HOST_VARIANT_SDK_default}"
871-
"${SWIFT_HOST_VARIANT_ARCH_default}"
869+
swift_icu_variables_set("${SWIFT_PRIMARY_VARIANT_SDK}"
870+
"${SWIFT_PRIMARY_VARIANT_ARCH}"
872871
ICU_CONFIGURED)
873872
if("${SWIFT_PATH_TO_LIBICU_BUILD}" STREQUAL "" AND NOT ${ICU_CONFIGURED})
874873
find_package(ICU REQUIRED COMPONENTS uc i18n)

trunk/include/swift/AST/PrintOptions.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,32 @@ struct PrintOptions {
135135
/// \brief Whether to print *any* accessors on properties.
136136
bool PrintPropertyAccessors = true;
137137

138-
/// \brief Whether to print the accessors of a property abstractly,
139-
/// i.e. always as get and set rather than the specific accessors
140-
/// actually used to implement the property.
138+
/// Whether to print the accessors of a property abstractly,
139+
/// i.e. always as:
140+
/// ```
141+
/// var x: Int { get set }
142+
/// ```
143+
/// rather than the specific accessors actually used to implement the
144+
/// property.
141145
///
142146
/// Printing function definitions takes priority over this setting.
143147
bool AbstractAccessors = true;
144148

149+
/// Whether to print a property with only a single getter using the shorthand
150+
/// ```
151+
/// var x: Int { return y }
152+
/// ```
153+
/// vs.
154+
/// ```
155+
/// var x: Int {
156+
/// get { return y }
157+
/// }
158+
/// ```
159+
bool CollapseSingleGetterProperty = true;
160+
161+
/// Whether to print the bodies of accessors in protocol context.
162+
bool PrintAccessorBodiesInProtocols = false;
163+
145164
/// \brief Whether to print type definitions.
146165
bool TypeDefinitions = false;
147166

trunk/include/swift/Runtime/Debug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ SWIFT_RUNTIME_ATTRIBUTE_NORETURN
8787
extern void
8888
fatalError(uint32_t flags, const char *format, ...);
8989

90+
/// swift::warning() emits a warning from the runtime.
91+
extern void
92+
warningv(uint32_t flags, const char *format, va_list args);
93+
9094
/// swift::warning() emits a warning from the runtime.
9195
extern void
9296
warning(uint32_t flags, const char *format, ...);

trunk/lib/AST/ASTPrinter.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ PrintOptions PrintOptions::printTextualInterfaceFile() {
8080
result.FullyQualifiedTypes = true;
8181
result.SkipImports = true;
8282
result.OmitNameOfInaccessibleProperties = true;
83+
result.FunctionDefinitions = true;
84+
result.CollapseSingleGetterProperty = false;
8385

8486
result.FunctionBody = [](const ValueDecl *decl, ASTPrinter &printer) {
8587
auto AFD = dyn_cast<AbstractFunctionDecl>(decl);
@@ -1579,15 +1581,15 @@ void PrintAST::printAccessors(AbstractStorageDecl *ASD) {
15791581
return;
15801582
}
15811583

1582-
// AbstractAccessors is suppressed by FunctionDefinitions, but not the
1583-
// presence of an FunctionBody callback.
1584+
// AbstractAccessors is suppressed by FunctionDefinitions.
15841585
bool PrintAbstract =
15851586
Options.AbstractAccessors && !Options.FunctionDefinitions;
15861587

15871588
// We sometimes want to print the accessors abstractly
15881589
// instead of listing out how they're actually implemented.
15891590
bool inProtocol = isa<ProtocolDecl>(ASD->getDeclContext());
1590-
if (!Options.FunctionBody && (inProtocol || PrintAbstract)) {
1591+
if ((inProtocol && !Options.PrintAccessorBodiesInProtocols) ||
1592+
PrintAbstract) {
15911593
bool mutatingGetter = ASD->getGetter() && ASD->isGetterMutating();
15921594
bool settable = ASD->isSettable(nullptr);
15931595
bool nonmutatingSetter = false;
@@ -1650,12 +1652,13 @@ void PrintAST::printAccessors(AbstractStorageDecl *ASD) {
16501652
}
16511653

16521654
// Otherwise, print all the concrete defining accessors.
1655+
bool PrintAccessorBody = Options.FunctionDefinitions;
16531656

1654-
bool PrintAccessorBody = Options.FunctionDefinitions || Options.FunctionBody;
1655-
1656-
auto PrintAccessor = [&](AccessorDecl *Accessor) {
1657-
if (!Accessor)
1658-
return;
1657+
// Helper to print an accessor. Returns true if the
1658+
// accessor was present but skipped.
1659+
auto PrintAccessor = [&](AccessorDecl *Accessor) -> bool {
1660+
if (!Accessor || !shouldPrint(Accessor))
1661+
return true;
16591662
if (!PrintAccessorBody) {
16601663
if (isAccessorAssumedNonMutating(Accessor->getAccessorKind())) {
16611664
if (Accessor->isMutating()) {
@@ -1679,19 +1682,17 @@ void PrintAST::printAccessors(AbstractStorageDecl *ASD) {
16791682
indent();
16801683
Printer.printNewline();
16811684
}
1685+
return false;
16821686
};
16831687

1684-
if ((PrintAbstract ||
1685-
(impl.getReadImpl() == ReadImplKind::Get && ASD->getGetter())) &&
1686-
!ASD->supportsMutation() && !ASD->isGetterMutating() &&
1687-
PrintAccessorBody && !Options.FunctionDefinitions) {
1688-
// Omit the 'get' keyword. Directly print getter
1689-
if (auto BodyFunc = Options.FunctionBody) {
1690-
BodyFunc(ASD->getGetter(), Printer);
1691-
indent();
1692-
return;
1693-
}
1694-
Printer.printNewline();
1688+
// Determine if we should print the getter without the 'get { ... }'
1689+
// block around it.
1690+
bool isOnlyGetter = impl.getReadImpl() == ReadImplKind::Get &&
1691+
ASD->getGetter();
1692+
bool isGetterMutating = ASD->supportsMutation() || ASD->isGetterMutating();
1693+
if (isOnlyGetter && !isGetterMutating && PrintAccessorBody &&
1694+
Options.FunctionBody && Options.CollapseSingleGetterProperty) {
1695+
Options.FunctionBody(ASD->getGetter(), Printer);
16951696
indent();
16961697
return;
16971698
}
@@ -1726,10 +1727,15 @@ void PrintAST::printAccessors(AbstractStorageDecl *ASD) {
17261727
case WriteImplKind::Stored:
17271728
llvm_unreachable("simply-stored variable should have been filtered out");
17281729
case WriteImplKind::StoredWithObservers:
1729-
case WriteImplKind::InheritedWithObservers:
1730-
PrintAccessor(ASD->getWillSetFunc());
1731-
PrintAccessor(ASD->getDidSetFunc());
1730+
case WriteImplKind::InheritedWithObservers: {
1731+
bool skippedWillSet = PrintAccessor(ASD->getWillSetFunc());
1732+
bool skippedDidSet = PrintAccessor(ASD->getDidSetFunc());
1733+
if (skippedDidSet && skippedWillSet) {
1734+
PrintAccessor(ASD->getGetter());
1735+
PrintAccessor(ASD->getSetter());
1736+
}
17321737
break;
1738+
}
17331739
case WriteImplKind::Set:
17341740
PrintAccessor(ASD->getSetter());
17351741
if (!shouldHideModifyAccessor())
@@ -1751,9 +1757,6 @@ void PrintAST::printAccessors(AbstractStorageDecl *ASD) {
17511757

17521758
Printer << "}";
17531759

1754-
if (!PrintAbstract)
1755-
Printer.printNewline();
1756-
17571760
indent();
17581761
}
17591762

trunk/lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,8 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
23972397
Options.AccessFilter = AccessLevel::Private;
23982398
Options.PrintAccess = false;
23992399
Options.SkipAttributes = true;
2400+
Options.FunctionDefinitions = true;
2401+
Options.PrintAccessorBodiesInProtocols = true;
24002402
Options.FunctionBody = [&](const ValueDecl *VD, ASTPrinter &Printer) {
24012403
Printer << " {";
24022404
Printer.printNewline();

trunk/stdlib/public/runtime/Errors.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,29 @@ swift::fatalError(uint32_t flags, const char *format, ...)
352352

353353
// Report a warning to system console and stderr.
354354
void
355-
swift::warning(uint32_t flags, const char *format, ...)
355+
swift::warningv(uint32_t flags, const char *format, va_list args)
356356
{
357-
va_list args;
358-
va_start(args, format);
359-
360357
char *log;
361358
#pragma GCC diagnostic push
362359
#pragma GCC diagnostic ignored "-Wuninitialized"
363360
swift_vasprintf(&log, format, args);
364361
#pragma GCC diagnostic pop
365-
362+
366363
reportNow(flags, log);
367-
364+
368365
free(log);
369366
}
370367

368+
// Report a warning to system console and stderr.
369+
void
370+
swift::warning(uint32_t flags, const char *format, ...)
371+
{
372+
va_list args;
373+
va_start(args, format);
374+
375+
warningv(flags, format, args);
376+
}
377+
371378
// Crash when a deleted method is called by accident.
372379
SWIFT_RUNTIME_EXPORT
373380
LLVM_ATTRIBUTE_NORETURN

trunk/stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/Basic/Lazy.h"
1314
#include "swift/Runtime/Reflection.h"
1415
#include "swift/Runtime/Casting.h"
1516
#include "swift/Runtime/Config.h"
@@ -253,6 +254,47 @@ AnyReturn subscript(intptr_t i, const char **outName,
253254
return AnyReturn(result);
254255
}
255256
};
257+
258+
struct swift_closure {
259+
void *fptr;
260+
HeapObject *context;
261+
};
262+
SWIFT_RUNTIME_STDLIB_API SWIFT_CC(swift) swift_closure
263+
MANGLE_SYM(s20_playgroundPrintHookySScSgvg)();
264+
265+
static bool _shouldReportMissingReflectionMetadataWarnings() {
266+
// Missing metadata warnings noise up playground sessions and aren't really
267+
// actionable in playground contexts. If we're running in a playground,
268+
// suppress warnings.
269+
//
270+
// Guesstimate whether we're in a playground by looking at the
271+
// _playgroundPrintHook variable in the standard library, which is set during
272+
// playground execution.
273+
auto hook = MANGLE_SYM(s20_playgroundPrintHookySScSgvg)();
274+
if (hook.fptr) {
275+
swift_release(hook.context);
276+
return false;
277+
} else {
278+
return true;
279+
}
280+
}
281+
282+
/// Raise a warning about reflection metadata that could not be found
283+
/// at runtime. This is usually mostly harmless, but it's good to alert
284+
/// users that it happens.
285+
static void
286+
missing_reflection_metadata_warning(const char *fmt, ...) {
287+
bool shouldWarn =
288+
SWIFT_LAZY_CONSTANT(_shouldReportMissingReflectionMetadataWarnings());
289+
290+
if (!shouldWarn)
291+
return;
292+
293+
va_list args;
294+
va_start(args, fmt);
295+
296+
warningv(0, fmt, args);
297+
}
256298

257299
static std::pair<StringRef /*name*/, FieldType /*fieldInfo*/>
258300
getFieldAt(const Metadata *base, unsigned index) {
@@ -262,9 +304,11 @@ AnyReturn subscript(intptr_t i, const char **outName,
262304
// back to returning an empty tuple as a standin.
263305
auto failedToFindMetadata = [&]() -> std::pair<StringRef, FieldType> {
264306
auto typeName = swift_getTypeName(base, /*qualified*/ true);
265-
warning(0, "SWIFT RUNTIME BUG: no field metadata for type '%*s' that claims "
266-
"to be reflectable\n",
267-
(int)typeName.length, typeName.data);
307+
missing_reflection_metadata_warning(
308+
"warning: the Swift runtime found no field metadata for "
309+
"type '%*s' that claims to be reflectable. Its fields will show up as "
310+
"'unknown' in Mirrors\n",
311+
(int)typeName.length, typeName.data);
268312
return {"unknown",
269313
FieldType()
270314
.withType(TypeInfo(&METADATA_SYM(EMPTY_TUPLE_MANGLING), {}))
@@ -331,10 +375,12 @@ AnyReturn subscript(intptr_t i, const char **outName,
331375
// a log message.
332376
if (typeInfo == nullptr) {
333377
typeInfo = TypeInfo(&METADATA_SYM(EMPTY_TUPLE_MANGLING), {});
334-
warning(0, "SWIFT RUNTIME BUG: unable to demangle type of field '%*s'. "
335-
"mangled type name is '%*s'\n",
336-
(int)name.size(), name.data(),
337-
(int)typeName.size(), typeName.data());
378+
missing_reflection_metadata_warning(
379+
"warning: the Swift runtime was unable to demangle the type "
380+
"of field '%*s'. the mangled type name is '%*s'. this field will "
381+
"show up as an empty tuple in Mirrors\n",
382+
(int)name.size(), name.data(),
383+
(int)typeName.size(), typeName.data());
338384
}
339385

340386
return {name, FieldType()

trunk/test/ModuleInterface/final.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// CHECK: final public class FinalClass {
77
public final class FinalClass {
88
// CHECK: @inlinable final public class var a: [[INT:(Swift.)?Int]] {
9+
// CHECK-NEXT: {{^}} get {
910
// CHECK-NEXT: return 3
1011
// CHECK-NEXT: }
12+
// CHECK-NEXT: }
1113
@inlinable
1214
public final class var a: Int {
1315
return 3

0 commit comments

Comments
 (0)