Skip to content

Commit 77e71d6

Browse files
authored
---
yaml --- r: 349220 b: refs/heads/master-next c: c6d51a9 h: refs/heads/master
1 parent 358364f commit 77e71d6

34 files changed

+836
-281
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 233f8645d1f8b82827278b2c8dfff902c2645765
3+
refs/heads/master-next: c6d51a975c1f68731da57fc5e893fccd3c4dfef2
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ function(_compile_swift_files
326326
set(sib_file "${module_base}.Onone.sib")
327327
set(sibopt_file "${module_base}.O.sib")
328328
set(sibgen_file "${module_base}.sibgen")
329-
list(APPEND swift_module_flags
330-
"-emit-module-source-info-path" "${source_info_file}")
331329

332330
if(SWIFT_ENABLE_MODULE_INTERFACES)
333331
set(interface_file "${module_base}.swiftinterface")
@@ -501,6 +499,7 @@ function(_compile_swift_files
501499
COMMAND
502500
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
503501
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"
502+
"-emit-module-source-info-path" "${source_info_file}"
504503
${swift_flags} ${swift_module_flags} "@${file_path}"
505504
${command_touch_module_outputs}
506505
OUTPUT ${module_outputs}

branches/master-next/include/swift/AST/Decl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
56895689
/// Note that a true return value does not imply that the body was actually
56905690
/// parsed.
56915691
bool hasBody() const {
5692-
return getBodyKind() != BodyKind::None;
5692+
return getBodyKind() != BodyKind::None &&
5693+
getBodyKind() != BodyKind::Skipped;
56935694
}
56945695

56955696
/// Returns true if the text of this function's body can be retrieved either
@@ -5716,14 +5717,22 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57165717
/// Note that the body was skipped for this function. Function body
57175718
/// cannot be attached after this call.
57185719
void setBodySkipped(SourceRange bodyRange) {
5719-
assert(getBodyKind() == BodyKind::None);
5720+
// FIXME: Remove 'Parsed' from this once we can delay parsing function
5721+
// bodies. Right now -experimental-skip-non-inlinable-function-bodies
5722+
// requires being able to change the state from Parsed to Skipped,
5723+
// because we're still eagerly parsing function bodies.
5724+
assert(getBodyKind() == BodyKind::None ||
5725+
getBodyKind() == BodyKind::Unparsed ||
5726+
getBodyKind() == BodyKind::Parsed);
5727+
assert(bodyRange.isValid());
57205728
BodyRange = bodyRange;
57215729
setBodyKind(BodyKind::Skipped);
57225730
}
57235731

57245732
/// Note that parsing for the body was delayed.
57255733
void setBodyDelayed(SourceRange bodyRange) {
57265734
assert(getBodyKind() == BodyKind::None);
5735+
assert(bodyRange.isValid());
57275736
BodyRange = bodyRange;
57285737
setBodyKind(BodyKind::Unparsed);
57295738
}
@@ -5769,6 +5778,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57695778
return getBodyKind() == BodyKind::TypeChecked;
57705779
}
57715780

5781+
bool isBodySkipped() const {
5782+
return getBodyKind() == BodyKind::Skipped;
5783+
}
5784+
57725785
bool isMemberwiseInitializer() const {
57735786
return getBodyKind() == BodyKind::MemberwiseInitializer;
57745787
}

branches/master-next/include/swift/AST/DeclContext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
409409
const_cast<DeclContext *>(this)->getInnermostDeclarationDeclContext();
410410
}
411411

412+
/// Returns the innermost context that is an AbstractFunctionDecl whose
413+
/// body has been skipped.
414+
LLVM_READONLY
415+
DeclContext *getInnermostSkippedFunctionContext();
416+
const DeclContext *getInnermostSkippedFunctionContext() const {
417+
return
418+
const_cast<DeclContext *>(this)->getInnermostSkippedFunctionContext();
419+
}
420+
412421
/// Returns the semantic parent of this context. A context has a
413422
/// parent if and only if it is not a module context.
414423
DeclContext *getParent() const {

branches/master-next/include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ ERROR(error_mode_cannot_emit_module_source_info,none,
128128
"this mode does not support emitting module source info files", ())
129129
ERROR(error_mode_cannot_emit_interface,none,
130130
"this mode does not support emitting module interface files", ())
131+
ERROR(cannot_emit_ir_skipping_function_bodies,none,
132+
"-experimental-skip-non-inlinable-function-bodies does not support "
133+
"emitting IR", ())
131134

132135
WARNING(emit_reference_dependencies_without_primary_file,none,
133136
"ignoring -emit-reference-dependencies (requires -primary-file)", ())

branches/master-next/include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class SILOptions {
7070
/// Whether to stop the optimization pipeline after serializing SIL.
7171
bool StopOptimizationAfterSerialization = false;
7272

73+
/// Whether to skip emitting non-inlinable function bodies.
74+
bool SkipNonInlinableFunctionBodies = false;
75+
7376
/// Optimization mode being used.
7477
OptimizationMode OptMode = OptimizationMode::NotSet;
7578

branches/master-next/include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class FrontendOptions {
180180
/// \sa swift::SharedTimer
181181
bool DebugTimeCompilation = false;
182182

183+
bool SkipNonInlinableFunctionBodies = false;
184+
183185
/// The path to which we should output statistics files.
184186
std::string StatsOutputDir;
185187

@@ -339,6 +341,7 @@ class FrontendOptions {
339341

340342
public:
341343
static bool doesActionGenerateSIL(ActionType);
344+
static bool doesActionGenerateIR(ActionType);
342345
static bool doesActionProduceOutput(ActionType);
343346
static bool doesActionProduceTextualOutput(ActionType);
344347
static bool needsProperModuleName(ActionType);

branches/master-next/include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ def stats_output_dir: Separate<["-"], "stats-output-dir">,
254254
def trace_stats_events: Flag<["-"], "trace-stats-events">,
255255
Flags<[FrontendOption, HelpHidden]>,
256256
HelpText<"Trace changes to stats in -stats-output-dir">;
257+
def experimental_skip_non_inlinable_function_bodies:
258+
Flag<["-"], "experimental-skip-non-inlinable-function-bodies">,
259+
Flags<[FrontendOption, HelpHidden]>,
260+
HelpText<"Skip type-checking and SIL generation for non-inlinable function bodies">;
257261
def profile_stats_events: Flag<["-"], "profile-stats-events">,
258262
Flags<[FrontendOption, HelpHidden]>,
259263
HelpText<"Profile changes to stats in -stats-output-dir">;

branches/master-next/include/swift/Reflection/ReflectionContext.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ class ReflectionContext
107107
using typename super::StoredPointer;
108108

109109
explicit ReflectionContext(std::shared_ptr<MemoryReader> reader)
110-
: super(std::move(reader)) {
111-
getBuilder().setMetadataReader(*this);
112-
}
110+
: super(std::move(reader), *this)
111+
{}
113112

114113
ReflectionContext(const ReflectionContext &other) = delete;
115114
ReflectionContext &operator=(const ReflectionContext &other) = delete;

branches/master-next/include/swift/Reflection/TypeRefBuilder.h

Lines changed: 56 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ class ReflectionSection {
6565
size_t size() const {
6666
return Size;
6767
}
68+
69+
bool containsRemoteAddress(uint64_t remoteAddr,
70+
uint64_t size) const {
71+
return Start.getAddressData() <= remoteAddr
72+
&& remoteAddr + size <= Start.getAddressData() + Size;
73+
}
74+
75+
template<typename U>
76+
RemoteRef<U> getRemoteRef(uint64_t remoteAddr) const {
77+
assert(containsRemoteAddress(remoteAddr, sizeof(U)));
78+
auto localAddr = (uint64_t)(uintptr_t)Start.getLocalBuffer()
79+
+ (remoteAddr - Start.getAddressData());
80+
81+
return RemoteRef<U>(remoteAddr, (const U*)localAddr);
82+
}
6883
};
6984

7085
template<typename Self, typename Descriptor>
@@ -239,17 +254,12 @@ class TypeRefBuilder {
239254
using BuiltTypeDecl = Optional<std::string>;
240255
using BuiltProtocolDecl = Optional<std::pair<std::string, bool /*isObjC*/>>;
241256

242-
TypeRefBuilder();
243-
244257
TypeRefBuilder(const TypeRefBuilder &other) = delete;
245258
TypeRefBuilder &operator=(const TypeRefBuilder &other) = delete;
246259

247260
private:
248261
Demangle::Demangler Dem;
249262

250-
std::function<const TypeRef* (const void*, unsigned)>
251-
OpaqueUnderlyingTypeReader;
252-
253263
/// Makes sure dynamically allocated TypeRefs stick around for the life of
254264
/// this TypeRefBuilder and are automatically released.
255265
std::vector<std::unique_ptr<const TypeRef>> TypeRefPool;
@@ -555,106 +565,66 @@ class TypeRefBuilder {
555565
return ReflectionInfos;
556566
}
557567

568+
public:
569+
enum ForTesting_t { ForTesting };
570+
571+
// Only for testing. A TypeRefBuilder built this way will not be able to
572+
// decode records in remote memory.
573+
explicit TypeRefBuilder(ForTesting_t) : TC(*this) {}
574+
558575
private:
559576
std::vector<ReflectionInfo> ReflectionInfos;
560-
561-
uint64_t getRemoteAddrOfTypeRefPointer(const void *pointer);
562-
563-
std::function<auto (SymbolicReferenceKind kind,
564-
Directness directness,
565-
int32_t offset, const void *base) -> Demangle::Node *>
566-
SymbolicReferenceResolver;
567-
577+
568578
std::string normalizeReflectionName(RemoteRef<char> name);
569579
bool reflectionNameMatches(RemoteRef<char> reflectionName,
570580
StringRef searchName);
571581

572582
public:
583+
RemoteRef<char> readTypeRef(uint64_t remoteAddr);
584+
573585
template<typename Record, typename Field>
574586
RemoteRef<char> readTypeRef(RemoteRef<Record> record,
575587
const Field &field) {
576588
uint64_t remoteAddr = record.resolveRelativeFieldData(field);
577-
// TODO: This assumes the remote and local buffer addresses are contiguous,
578-
// which should not be a guarantee that MemoryReaders need to maintain.
579-
// Ultimately this should use the MemoryReader to read the string.
580-
auto localAddr = (uint64_t)(uintptr_t)record.getLocalBuffer()
581-
+ (int64_t)(remoteAddr - record.getAddressData());
582-
583-
// Skip the mangling prefix, if any.
584-
auto localPtr = (const char *)localAddr;
585-
if (localPtr[0] == '$' && localPtr[1] == 's') {
586-
remoteAddr += 2;
587-
localPtr += 2;
588-
}
589589

590-
return RemoteRef<char>(remoteAddr, localPtr);
590+
return readTypeRef(remoteAddr);
591591
}
592-
592+
593593
StringRef getTypeRefString(RemoteRef<char> record) {
594594
return Demangle::makeSymbolicMangledNameStringRef(record.getLocalBuffer());
595595
}
596596

597-
Demangle::Node *demangleTypeRef(RemoteRef<char> string) {
598-
// TODO: Use the remote addr in the RemoteRef to resolve and read from
599-
// remote addresses in the resolver function.
600-
return Dem.demangleType(getTypeRefString(string),
601-
SymbolicReferenceResolver);
602-
}
597+
private:
598+
// These fields are captured from the MetadataReader template passed into the
599+
// TypeRefBuilder struct, to isolate its template-ness from the rest of
600+
// TypeRefBuilder.
601+
unsigned PointerSize;
602+
std::function<Demangle::Node * (RemoteRef<char>)>
603+
TypeRefDemangler;
604+
std::function<const TypeRef* (const void*, unsigned)>
605+
OpaqueUnderlyingTypeReader;
603606

607+
public:
604608
template<typename Runtime>
605-
void setMetadataReader(
606-
remote::MetadataReader<Runtime, TypeRefBuilder> &reader) {
607-
// Have the TypeRefBuilder demangle symbolic references by reading their
608-
// demangling out of the referenced context descriptors in the target
609-
// process.
610-
SymbolicReferenceResolver =
611-
[this, &reader](SymbolicReferenceKind kind,
612-
Directness directness,
613-
int32_t offset, const void *base) -> Demangle::Node * {
614-
// Resolve the reference to a remote address.
615-
auto remoteAddress = getRemoteAddrOfTypeRefPointer(base);
616-
if (remoteAddress == 0)
617-
return nullptr;
618-
619-
auto address = remoteAddress + offset;
620-
if (directness == Directness::Indirect) {
621-
if (auto indirectAddress = reader.readPointerValue(address)) {
622-
address = *indirectAddress;
623-
} else {
624-
return nullptr;
625-
}
626-
}
627-
628-
switch (kind) {
629-
case Demangle::SymbolicReferenceKind::Context: {
630-
auto context = reader.readContextDescriptor(address);
631-
if (!context)
632-
return nullptr;
633-
// Try to preserve a reference to an OpaqueTypeDescriptor symbolically,
634-
// since we'd like to read out and resolve the type ref to the
635-
// underlying type if available.
636-
if (context->getKind() == ContextDescriptorKind::OpaqueType) {
637-
return Dem.createNode(
638-
Node::Kind::OpaqueTypeDescriptorSymbolicReference,
639-
context.getAddressData());
640-
}
641-
642-
return reader.buildContextMangling(context, Dem);
643-
}
644-
case Demangle::SymbolicReferenceKind::AccessorFunctionReference:
645-
// The symbolic reference points at a resolver function, but we can't
646-
// execute code in the target process to resolve it from here.
647-
return nullptr;
648-
}
649-
650-
return nullptr;
651-
};
652-
653-
OpaqueUnderlyingTypeReader =
654-
[&reader](const void *descriptor, unsigned ordinal) -> const TypeRef* {
655-
auto context = (typename Runtime::StoredPointer)descriptor;
656-
return reader.readUnderlyingTypeForOpaqueTypeDescriptor(context, ordinal);
657-
};
609+
TypeRefBuilder(remote::MetadataReader<Runtime, TypeRefBuilder> &reader)
610+
: TC(*this),
611+
PointerSize(sizeof(typename Runtime::StoredPointer)),
612+
TypeRefDemangler(
613+
[this, &reader](RemoteRef<char> string) -> Demangle::Node * {
614+
return reader.demangle(string,
615+
remote::MangledNameKind::Type,
616+
Dem, /*useOpaqueTypeSymbolicReferences*/ true);
617+
}),
618+
OpaqueUnderlyingTypeReader(
619+
[&reader](const void *descriptor, unsigned ordinal) -> const TypeRef* {
620+
auto context = (typename Runtime::StoredPointer)descriptor;
621+
return reader.readUnderlyingTypeForOpaqueTypeDescriptor(context,
622+
ordinal);
623+
})
624+
{}
625+
626+
Demangle::Node *demangleTypeRef(RemoteRef<char> string) {
627+
return TypeRefDemangler(string);
658628
}
659629

660630
TypeConverter &getTypeConverter() { return TC; }

0 commit comments

Comments
 (0)