Skip to content

Commit 95529a7

Browse files
authored
Merge pull request #1254 from swiftwasm/master
[pull] swiftwasm from master
2 parents a8a3eee + 0b7fea6 commit 95529a7

File tree

54 files changed

+795
-169
lines changed

Some content is hidden

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

54 files changed

+795
-169
lines changed

include/swift/AST/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
swift_install_in_component(DIRECTORY diagnostics
2+
DESTINATION "share/swift/"
3+
COMPONENT compiler)

include/swift/AST/DiagnosticEngine.h

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ namespace swift {
5858
DiagID ID;
5959
};
6060

61+
struct DiagnosticNode {
62+
DiagID id;
63+
std::string msg;
64+
};
65+
6166
namespace detail {
6267
/// Describes how to pass a diagnostic argument of the given type.
6368
///
@@ -629,7 +634,26 @@ namespace swift {
629634
DiagnosticState(DiagnosticState &&) = default;
630635
DiagnosticState &operator=(DiagnosticState &&) = default;
631636
};
632-
637+
638+
class LocalizationProducer {
639+
public:
640+
/// If the message isn't available/localized in the current `yaml` file,
641+
/// return the fallback default message.
642+
virtual std::string getMessageOr(DiagID id,
643+
std::string defaultMessage) const {
644+
return defaultMessage;
645+
}
646+
647+
virtual ~LocalizationProducer() {}
648+
};
649+
650+
class YAMLLocalizationProducer final : public LocalizationProducer {
651+
public:
652+
std::vector<std::string> diagnostics;
653+
explicit YAMLLocalizationProducer(std::string locale, std::string path);
654+
std::string getMessageOr(DiagID id,
655+
std::string defaultMessage) const override;
656+
};
633657
/// Class responsible for formatting diagnostics and presenting them
634658
/// to the user.
635659
class DiagnosticEngine {
@@ -663,6 +687,10 @@ namespace swift {
663687
/// but rather stored until all transactions complete.
664688
llvm::StringSet<llvm::BumpPtrAllocator &> TransactionStrings;
665689

690+
/// Diagnostic producer to handle the logic behind retriving a localized
691+
/// diagnostic message.
692+
std::unique_ptr<LocalizationProducer> localization;
693+
666694
/// The number of open diagnostic transactions. Diagnostics are only
667695
/// emitted once all transactions have closed.
668696
unsigned TransactionCount = 0;
@@ -734,6 +762,11 @@ namespace swift {
734762
return diagnosticDocumentationPath;
735763
}
736764

765+
void setLocalization(std::string locale, std::string path) {
766+
if (!locale.empty() && !path.empty())
767+
localization = std::make_unique<YAMLLocalizationProducer>(locale, path);
768+
}
769+
737770
void ignoreDiagnostic(DiagID id) {
738771
state.setDiagnosticBehavior(id, DiagnosticState::Behavior::Ignore);
739772
}
@@ -955,8 +988,7 @@ namespace swift {
955988
void emitTentativeDiagnostics();
956989

957990
public:
958-
static const char *diagnosticStringFor(const DiagID id,
959-
bool printDiagnosticName);
991+
const char *diagnosticStringFor(const DiagID id, bool printDiagnosticName);
960992

961993
/// If there is no clear .dia file for a diagnostic, put it in the one
962994
/// corresponding to the SourceLoc given here.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- DiagnosticMessageFormat.h - YAML format for Diagnostic Messages ---*-
2+
//C++ -*-===//
3+
//
4+
// This source file is part of the Swift.org open source project
5+
//
6+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
7+
// Licensed under Apache License v2.0 with Runtime Library Exception
8+
//
9+
// See https://swift.org/LICENSE.txt for license information
10+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
//
12+
//===----------------------------------------------------------------------===//
13+
//
14+
// This file defines the YAML format for diagnostic messages.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#include "DiagnosticList.cpp"
19+
#include "llvm/Support/YAMLTraits.h"
20+
21+
namespace llvm {
22+
namespace yaml {
23+
24+
template <> struct ScalarEnumerationTraits<swift::DiagID> {
25+
static void enumeration(IO &io, swift::DiagID &value) {
26+
#define DIAG(KIND, ID, Options, Text, Signature) \
27+
io.enumCase(value, #ID, swift::DiagID::ID);
28+
#include "swift/AST/DiagnosticsAll.def"
29+
}
30+
};
31+
32+
template <> struct MappingTraits<swift::DiagnosticNode> {
33+
static void mapping(IO &io, swift::DiagnosticNode &node) {
34+
io.mapRequired("id", node.id);
35+
io.mapRequired("msg", node.msg);
36+
}
37+
};
38+
39+
} // namespace yaml
40+
} // namespace llvm
41+
42+
LLVM_YAML_IS_SEQUENCE_VECTOR(swift::DiagnosticNode)

include/swift/AST/Diagnostics/fr.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#===--- fr.yaml - Localized diagnostic messages for French ---*- YAML -*-===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 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 the diagnostic messages for French language.
14+
# Each diagnostic is described in the following format:
15+
# - id: <diagnostic-id>
16+
# msg: <diagnostic-message>
17+
#
18+
#===----------------------------------------------------------------------===#
19+

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ ERROR(previous_installname_map_corrupted,none,
247247
"previous install name map from %0 is malformed",
248248
(StringRef))
249249

250+
ERROR(explicit_swift_module_map_missing,none,
251+
"cannot open explicit Swift module map from %0",
252+
(StringRef))
253+
254+
ERROR(explicit_swift_module_map_corrupted,none,
255+
"explicit Swift module map from %0 is malformed",
256+
(StringRef))
257+
250258
REMARK(default_previous_install_name, none,
251259
"default previous install name for %0 is %1", (StringRef, StringRef))
252260

include/swift/AST/SearchPathOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SearchPathOptions {
8585
/// The paths to a set of explicitly built modules from interfaces.
8686
std::vector<std::string> ExplicitSwiftModules;
8787

88+
/// A map of explict Swift module information.
89+
std::string ExplicitSwiftModuleMap;
8890
private:
8991
static StringRef
9092
pathStringFromFrameworkSearchPath(const FrameworkSearchPath &next) {

include/swift/AST/diagnostics/en.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#===--- en.yaml - Localized diagnostic messages for English ---*- YAML -*-===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 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 the diagnostic messages for English language.
14+
# Each diagnostic is described in the following format:
15+
# - id: <diagnostic-id>
16+
# msg: <diagnostic-message>
17+
#
18+
#===----------------------------------------------------------------------===#
19+

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class ExplicitSwiftModuleLoader: public SerializedModuleLoaderBase {
150150
create(ASTContext &ctx,
151151
DependencyTracker *tracker, ModuleLoadingMode loadMode,
152152
ArrayRef<std::string> ExplicitModulePaths,
153+
StringRef ExplicitSwiftModuleMap,
153154
bool IgnoreSwiftSourceInfoFile);
154155

155156
/// Append visible module names to \p names. Note that names are possibly

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ def disable_implicit_swift_modules: Flag<["-"], "disable-implicit-swift-modules"
220220
def swift_module_file
221221
: Separate<["-"], "swift-module-file">, MetaVarName<"<path>">,
222222
HelpText<"Specify Swift module explicitly built from textual interface">;
223+
224+
def explict_swift_module_map
225+
: Separate<["-"], "explicit-swift-module-map-file">, MetaVarName<"<path>">,
226+
HelpText<"Specify a JSON file containing information of explict Swift modules">;
223227
}
224228

225229

include/swift/Reflection/ReflectionContext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,18 @@ class ReflectionContext
838838
return 0;
839839
}
840840

841+
/// Get the name of a metadata tag, if known.
842+
llvm::Optional<std::string> metadataAllocationTagName(int Tag) {
843+
switch (Tag) {
844+
#define TAG(name, value) \
845+
case value: \
846+
return std::string(#name);
847+
#include "../../../stdlib/public/runtime/MetadataAllocatorTags.def"
848+
default:
849+
return llvm::None;
850+
}
851+
}
852+
841853
/// Iterate the metadata allocations in the target process, calling Call with
842854
/// each allocation found. Returns None on success, and a string describing
843855
/// the error on failure.

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,9 @@ namespace swift {
2929
// allocator. This is encoded in a header on each allocation when metadata
3030
// iteration is enabled, and allows tools to know where each allocation came
3131
// from.
32-
//
33-
// Some of these values are also declared in SwiftRemoteMirrorTypes.h. Those
34-
// values must be kept stable to preserve compatibility.
3532
enum MetadataAllocatorTags : uint16_t {
36-
UnusedTag = 0,
37-
BoxesTag,
38-
ObjCClassWrappersTag,
39-
FunctionTypesTag,
40-
MetatypeTypesTag,
41-
ExistentialMetatypeValueWitnessTablesTag,
42-
ExistentialMetatypesTag,
43-
ExistentialTypesTag,
44-
OpaqueExistentialValueWitnessTablesTag,
45-
ClassExistentialValueWitnessTablesTag,
46-
ForeignWitnessTablesTag,
47-
ResilientMetadataAllocatorTag,
48-
MetadataTag,
49-
TupleCacheTag,
50-
GenericMetadataCacheTag,
51-
ForeignMetadataCacheTag,
52-
GenericWitnessTableCacheTag,
53-
GenericClassMetadataTag,
54-
GenericValueMetadataTag,
33+
#define TAG(name, value) name##Tag = value,
34+
#include "../../../stdlib/public/runtime/MetadataAllocatorTags.def"
5535
};
5636

5737
template <typename Runtime> struct MetadataAllocationBacktraceHeader {

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,24 @@ const char *swift_reflection_iterateMetadataAllocations(
324324
/// Given a metadata allocation, return the metadata it points to. Returns NULL
325325
/// on failure. Despite the name, not all allocations point to metadata.
326326
/// Currently, this will return a metadata only for allocations with tag
327-
/// SWIFT_GENERIC_METADATA_CACHE_ALLOCATION. Support for additional tags may be
328-
/// added in the future. The caller must gracefully handle failure.
327+
/// GenericMetadataCache. Support for additional tags may be added in the
328+
/// future. The caller must gracefully handle failure.
329329
SWIFT_REMOTE_MIRROR_LINKAGE
330330
swift_reflection_ptr_t swift_reflection_allocationMetadataPointer(
331331
SwiftReflectionContextRef ContextRef,
332332
swift_metadata_allocation_t Allocation);
333333

334+
/// Return the name of a metadata allocation tag, or NULL if the tag is unknown.
335+
/// This pointer remains valid until the next swift_reflection call on the given
336+
/// context.
337+
SWIFT_REMOTE_MIRROR_LINKAGE
338+
const char *
339+
swift_reflection_metadataAllocationTagName(SwiftReflectionContextRef ContextRef,
340+
swift_metadata_allocation_tag_t Tag);
341+
334342
/// Backtrace iterator callback passed to
335343
/// swift_reflection_iterateMetadataAllocationBacktraces
336-
typedef void (*swift_metadataAllocationIterator)(
344+
typedef void (*swift_metadataAllocationBacktraceIterator)(
337345
swift_reflection_ptr_t AllocationPtr, size_t Count,
338346
const swift_reflection_ptr_t Ptrs[], void *ContextPtr);
339347

@@ -350,8 +358,8 @@ typedef void (*swift_metadataAllocationIterator)(
350358
/// swift_reflection call on the given context.
351359
SWIFT_REMOTE_MIRROR_LINKAGE
352360
const char *swift_reflection_iterateMetadataAllocationBacktraces(
353-
SwiftReflectionContextRef ContextRef, swift_metadataAllocationIterator Call,
354-
void *ContextPtr);
361+
SwiftReflectionContextRef ContextRef,
362+
swift_metadataAllocationBacktraceIterator Call, void *ContextPtr);
355363

356364
#ifdef __cplusplus
357365
} // extern "C"

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,10 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
18841884

18851885
void visitCodeCompletionExpr(CodeCompletionExpr *E) {
18861886
printCommon(E, "code_completion_expr");
1887+
if (E->getBase()) {
1888+
OS << '\n';
1889+
printRec(E->getBase());
1890+
}
18871891
PrintWithColorRAII(OS, ParenthesisColor) << ')';
18881892
}
18891893

lib/AST/Attr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,8 @@ void DifferentiableAttr::setParameterIndices(IndexSubset *paramIndices) {
17111711

17121712
GenericEnvironment *DifferentiableAttr::getDerivativeGenericEnvironment(
17131713
AbstractFunctionDecl *original) const {
1714-
GenericEnvironment *derivativeGenEnv = original->getGenericEnvironment();
17151714
if (auto derivativeGenSig = getDerivativeGenericSignature())
1716-
return derivativeGenEnv = derivativeGenSig->getGenericEnvironment();
1715+
return derivativeGenSig->getGenericEnvironment();
17171716
return original->getGenericEnvironment();
17181717
}
17191718

0 commit comments

Comments
 (0)