Skip to content

Commit 7855b4e

Browse files
Merge pull request #44 from kateinoigakukun/merge/2b5fa680086f0d04a5364fb1b6590c36b3c2a86a
Merge 2b5fa68
2 parents 502bf8e + bc8ee9f commit 7855b4e

File tree

91 files changed

+3143
-1678
lines changed

Some content is hidden

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

91 files changed

+3143
-1678
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -375,30 +375,6 @@ function(_add_variant_c_compile_flags)
375375
endforeach()
376376
endif()
377377

378-
set(ICU_UC_INCLUDE_DIR ${SWIFT_${CFLAGS_SDK}_${CFLAGS_ARCH}_ICU_UC_INCLUDE})
379-
if(NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "" AND
380-
NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/include" AND
381-
NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_TRIPLE}/include" AND
382-
NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_TRIPLE}/include")
383-
if(SWIFT_COMPILER_IS_MSVC_LIKE)
384-
list(APPEND result -I;${ICU_UC_INCLUDE_DIR})
385-
else()
386-
list(APPEND result -isystem;${ICU_UC_INCLUDE_DIR})
387-
endif()
388-
endif()
389-
390-
set(ICU_I18N_INCLUDE_DIR ${SWIFT_${CFLAGS_SDK}_${CFLAGS_ARCH}_ICU_I18N_INCLUDE})
391-
if(NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "" AND
392-
NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/include" AND
393-
NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_TRIPLE}/include" AND
394-
NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_TRIPLE}/include")
395-
if(SWIFT_COMPILER_IS_MSVC_LIKE)
396-
list(APPEND result -I;${ICU_I18N_INCLUDE_DIR})
397-
else()
398-
list(APPEND result -isystem;${ICU_I18N_INCLUDE_DIR})
399-
endif()
400-
endif()
401-
402378
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
403379
endfunction()
404380

@@ -1427,6 +1403,9 @@ function(_add_swift_library_single target name)
14271403
endif()
14281404

14291405
# Set compilation and link flags.
1406+
target_include_directories(${target} SYSTEM PRIVATE
1407+
${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_UC_INCLUDE}
1408+
${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_I18N_INCLUDE})
14301409
target_compile_options(${target} PRIVATE
14311410
${c_compile_flags})
14321411
target_link_options(${target} PRIVATE
@@ -1501,7 +1480,7 @@ function(_add_swift_library_single target name)
15011480
endif()
15021481

15031482
if(target_static)
1504-
target_link_options(${target_static} PRIVATE
1483+
target_compile_options(${target_static} PRIVATE
15051484
${c_compile_flags})
15061485
# FIXME: The fallback paths here are going to be dynamic libraries.
15071486

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
5353
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)
5454
SWIFT_TYPEID_NAMED(ValueDecl *, ValueDecl)
5555
SWIFT_TYPEID_NAMED(VarDecl *, VarDecl)
56+
SWIFT_TYPEID(FingerprintAndMembers)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct TypePair;
6161
struct TypeWitnessAndDecl;
6262
enum class AncestryFlags : uint8_t;
6363
enum class ImplicitMemberAction : uint8_t;
64+
struct FingerprintAndMembers;
6465

6566
// Define the AST type zone (zone 1)
6667
#define SWIFT_TYPEID_ZONE AST

include/swift/AST/DeclContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ class IterableDeclContext {
802802
// Some Decls are IterableDeclContexts, but not all.
803803
static bool classof(const Decl *D);
804804

805+
/// Return a hash of all tokens in the body for dependency analysis, if
806+
/// available.
807+
Optional<std::string> getBodyFingerprint() const;
808+
809+
bool areDependenciesUsingTokenHashesForTypeBodies() const;
810+
805811
private:
806812
/// Add a member to the list for iteration purposes, but do not notify the
807813
/// subclass that we have done so.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ ERROR(error_unknown_arg,none,
9494
"unknown argument: '%0'", (StringRef))
9595
ERROR(error_invalid_arg_value,none,
9696
"invalid value '%1' in '%0'", (StringRef, StringRef))
97+
WARNING(warning_type_fingerprints_require_fine_grained_dependencies,none,
98+
"Type fingerprints require fine-grained dependencies", ())
9799
WARNING(warning_cannot_multithread_batch_mode,none,
98100
"ignoring -num-threads argument; cannot multithread batch mode", ())
99101
ERROR(error_unsupported_option_argument,none,

include/swift/AST/FineGrainedDependencies.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/Debug.h"
1717
#include "swift/Basic/LLVM.h"
18+
#include "swift/Basic/NullablePtr.h"
1819
#include "swift/Basic/Range.h"
1920
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/Support/MD5.h"
@@ -139,6 +140,11 @@ template <typename Key1, typename Key2, typename Value> class TwoStageMap {
139140
return iter2 == iter->second.end() ? None : Optional<Value>(iter2->second);
140141
}
141142

143+
NullablePtr<const InnerMap> find(const Key1 &k1) const {
144+
auto iter = map.find(k1);
145+
return iter == map.end() ? nullptr : &iter->second;
146+
}
147+
142148
/// The sought value must be present.
143149
Value findAndErase(const Key1 &k1, const Key2 &k2) {
144150
auto &submap = map[k1];
@@ -237,6 +243,20 @@ class BiIndexedTwoStageMap {
237243
}
238244
Optional<Value> find(const Key2 &k2, Key1 &k1) const { return find(k1, k2); }
239245

246+
/// Return the submap for a given Key1. May create one, after the fashion of
247+
/// the standard libary.
248+
const Key2Map &operator[](const Key1 &k1) { return map1[k1]; }
249+
/// Return the submap for a given Key2. May create one, after the fashion of
250+
/// the standard libary.
251+
const Key1Map &operator[](const Key2 &k2) { return map2[k2]; }
252+
253+
NullablePtr<const Key2Map> find(const Key1 &k1) const {
254+
return map1.find(k1);
255+
}
256+
NullablePtr<const Key1Map> find(const Key2 &k2) const {
257+
return map2.find(k2);
258+
}
259+
240260
/// Element must be present.
241261
/// Return the erased value.
242262
Value findAndErase(const Key1 &k1, const Key2 &k2) {
@@ -250,12 +270,6 @@ class BiIndexedTwoStageMap {
250270
Value findAndErase(const Key2 &k2, const Key1 &k1) {
251271
return findAndErase(k1, k2);
252272
}
253-
/// Return the submap for a given Key1. May create one, after the fashion of
254-
/// the standard libary.
255-
const Key2Map &operator[](const Key1 &k1) { return map1[k1]; }
256-
/// Return the submap for a given Key2. May create one, after the fashion of
257-
/// the standard libary.
258-
const Key1Map &operator[](const Key2 &k2) { return map2[k2]; }
259273

260274
/// Invoke \p fn on each Key2 and Value matching (\p k1, *)
261275
void forEachValueMatching(
@@ -500,8 +514,7 @@ class DependencyKey {
500514
template <NodeKind kind>
501515
static DependencyKey createDependedUponKey(StringRef);
502516

503-
static DependencyKey
504-
createTransitiveKeyForWholeSourceFile(StringRef swiftDeps);
517+
static DependencyKey createKeyForWholeSourceFile(StringRef swiftDeps);
505518

506519
std::string humanReadableName() const;
507520

@@ -787,6 +800,12 @@ class SourceFileDepGraph {
787800

788801
static constexpr char noncascadingOrPrivatePrefix = '#';
789802

803+
static std::string noncascading(std::string name);
804+
805+
LLVM_ATTRIBUTE_UNUSED
806+
static std::string privatize(std::string name);
807+
808+
790809
/// Nodes are owned by the graph.
791810
~SourceFileDepGraph() {
792811
forEachNode([&](SourceFileDepGraphNode *n) { delete n; });

include/swift/AST/ParseRequests.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,31 @@ template<typename Request>
2727
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
2828
const Request &request);
2929

30+
struct FingerprintAndMembers {
31+
Optional<std::string> fingerprint = None;
32+
ArrayRef<Decl *> members = {};
33+
bool operator==(const FingerprintAndMembers &x) const {
34+
return fingerprint == x.fingerprint && members == x.members;
35+
}
36+
};
37+
38+
void simple_display(llvm::raw_ostream &out, const FingerprintAndMembers &value);
39+
3040
/// Parse the members of a nominal type declaration or extension.
31-
class ParseMembersRequest :
32-
public SimpleRequest<ParseMembersRequest,
33-
ArrayRef<Decl *>(IterableDeclContext *),
34-
CacheKind::Cached>
35-
{
41+
/// Return a fingerprint and the members.
42+
class ParseMembersRequest
43+
: public SimpleRequest<ParseMembersRequest,
44+
FingerprintAndMembers(IterableDeclContext *),
45+
CacheKind::Cached> {
3646
public:
3747
using SimpleRequest::SimpleRequest;
3848

3949
private:
4050
friend SimpleRequest;
4151

4252
// Evaluation.
43-
ArrayRef<Decl *> evaluate(Evaluator &evaluator,
44-
IterableDeclContext *idc) const;
53+
FingerprintAndMembers evaluate(Evaluator &evaluator,
54+
IterableDeclContext *idc) const;
4555

4656
public:
4757
// Caching

include/swift/AST/ParseTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
SWIFT_REQUEST(Parse, ParseMembersRequest,
18-
ArrayRef<Decl *>(IterableDeclContext *), Cached, NoLocationInfo)
18+
FingerprintAndMembers(IterableDeclContext *), Cached, NoLocationInfo)
1919
SWIFT_REQUEST(Parse, ParseAbstractFunctionBodyRequest,
2020
BraceStmt *(AbstractFunctionDecl *), SeparatelyCached,
2121
NoLocationInfo)

include/swift/AST/SILGenRequests.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//===--- SILGenRequests.h - SILGen Requests ---------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines SILGen requests.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_SILGEN_REQUESTS_H
18+
#define SWIFT_SILGEN_REQUESTS_H
19+
20+
#include "swift/AST/ASTTypeIDs.h"
21+
#include "swift/AST/SimpleRequest.h"
22+
23+
namespace swift {
24+
25+
class FileUnit;
26+
class LangOptions;
27+
class ModuleDecl;
28+
class SILModule;
29+
class SILOptions;
30+
class SourceFile;
31+
32+
namespace Lowering {
33+
class TypeConverter;
34+
}
35+
36+
/// Report that a request of the given kind is being evaluated, so it
37+
/// can be recorded by the stats reporter.
38+
template<typename Request>
39+
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
40+
const Request &request);
41+
42+
struct SILGenDescriptor {
43+
llvm::PointerUnion<ModuleDecl *, FileUnit *> context;
44+
Lowering::TypeConverter &conv;
45+
const SILOptions &opts;
46+
47+
friend llvm::hash_code hash_value(const SILGenDescriptor &owner) {
48+
return llvm::hash_combine(owner.context, (void *)&owner.conv,
49+
(void *)&owner.opts);
50+
}
51+
52+
friend bool operator==(const SILGenDescriptor &lhs,
53+
const SILGenDescriptor &rhs) {
54+
return lhs.context == rhs.context &&
55+
&lhs.conv == &rhs.conv &&
56+
&lhs.opts == &rhs.opts;
57+
}
58+
59+
friend bool operator!=(const SILGenDescriptor &lhs,
60+
const SILGenDescriptor &rhs) {
61+
return !(lhs == rhs);
62+
}
63+
64+
public:
65+
static SILGenDescriptor forFile(FileUnit &sf, Lowering::TypeConverter &conv,
66+
const SILOptions &opts) {
67+
return SILGenDescriptor{&sf, conv, opts};
68+
}
69+
70+
static SILGenDescriptor forWholeModule(ModuleDecl *mod,
71+
Lowering::TypeConverter &conv,
72+
const SILOptions &opts) {
73+
return SILGenDescriptor{mod, conv, opts};
74+
}
75+
};
76+
77+
class GenerateSILRequest :
78+
public SimpleRequest<GenerateSILRequest,
79+
std::unique_ptr<SILModule>(SILGenDescriptor),
80+
CacheKind::Uncached> {
81+
public:
82+
using SimpleRequest::SimpleRequest;
83+
84+
private:
85+
friend SimpleRequest;
86+
87+
// Evaluation.
88+
llvm::Expected<std::unique_ptr<SILModule>>
89+
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
90+
91+
public:
92+
bool isCached() const { return true; }
93+
};
94+
95+
void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);
96+
97+
SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc);
98+
99+
/// The zone number for SILGen.
100+
#define SWIFT_TYPEID_ZONE SILGen
101+
#define SWIFT_TYPEID_HEADER "swift/AST/SILGenTypeIDZone.def"
102+
#include "swift/Basic/DefineTypeIDZone.h"
103+
#undef SWIFT_TYPEID_ZONE
104+
#undef SWIFT_TYPEID_HEADER
105+
106+
// Set up reporting of evaluated requests.
107+
#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
108+
template<> \
109+
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
110+
const RequestType &request) { \
111+
++stats.getFrontendCounters().RequestType; \
112+
}
113+
#include "swift/AST/SILGenTypeIDZone.def"
114+
#undef SWIFT_REQUEST
115+
116+
} // end namespace swift
117+
118+
#endif // SWIFT_SILGEN_REQUESTS_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- SILGenTypeIDZone.def -----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the requests in SILGen's zone.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
SWIFT_REQUEST(SILGen, GenerateSILRequest,
18+
std::unique_ptr<SILModule>(SILGenDescriptor),
19+
Uncached, NoLocationInfo)

include/swift/AST/SourceFile.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,8 @@ class SourceFile final : public FileUnit {
423423
return InterfaceHash.hasValue();
424424
}
425425

426-
void recordInterfaceToken(StringRef token) {
427-
assert(!token.empty());
428-
InterfaceHash->update(token);
429-
// Add null byte to separate tokens.
430-
uint8_t a[1] = {0};
431-
InterfaceHash->update(a);
426+
NullablePtr<llvm::MD5> getInterfaceHashPtr() {
427+
return InterfaceHash ? InterfaceHash.getPointer() : nullptr;
432428
}
433429

434430
void getInterfaceHash(llvm::SmallString<32> &str) const {

include/swift/Basic/CTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SWIFT_TYPEID_NAMED(std::string, String)
3636

3737
// C++ standard library types.
3838
SWIFT_TYPEID_TEMPLATE1_NAMED(std::vector, Vector, typename T, T)
39+
SWIFT_TYPEID_TEMPLATE1_NAMED(std::unique_ptr, UniquePtr, typename T, T)
3940

4041
// LLVM ADT types.
4142
SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::TinyPtrVector, TinyPtrVector, typename T, T)

include/swift/Basic/LangOptions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,14 @@ namespace swift {
298298

299299
/// Emit the newer, finer-grained swiftdeps file. Eventually will support
300300
/// faster rebuilds.
301-
/// The initializer here sets the default for the frontend and driver.
302301
bool EnableFineGrainedDependencies = true;
303302

303+
/// Instead of hashing tokens inside of NominalType and ExtensionBodies into
304+
/// the interface hash, hash them into per-iterable-decl-context
305+
/// fingerprints. Fine-grained dependency types won't dirty every provides
306+
/// in a file when the user adds a member to, e.g., a struct.
307+
bool EnableTypeFingerprints = false;
308+
304309
/// When using fine-grained dependencies, emit dot files for every swiftdeps
305310
/// file.
306311
bool EmitFineGrainedDependencySourcefileDotFiles = false;

include/swift/Basic/Statistic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class SourceFile;
6969
class SourceManager;
7070
class Stmt;
7171
class TypeRepr;
72+
struct FingerprintAndMembers;
7273

7374
// There are a handful of cases where the swift compiler can introduce
7475
// counter-measurement noise via nondeterminism, especially via

0 commit comments

Comments
 (0)