Skip to content

Commit 1d4395b

Browse files
Merge pull request #5529 from swiftwasm/main
[pull] swiftwasm from main
2 parents 35ad79e + 79616c4 commit 1d4395b

File tree

669 files changed

+2856
-1404
lines changed

Some content is hidden

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

669 files changed

+2856
-1404
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ private func optimize(function: Function, _ context: FunctionPassContext) {
5858
switch instruction {
5959
case let apply as FullApplySite:
6060
inlineAndDevirtualize(apply: apply, context, simplifyCtxt)
61-
case let mt as MetatypeInst:
62-
if mt.isTriviallyDeadIgnoringDebugUses {
63-
simplifyCtxt.erase(instructionIncludingDebugUses: mt)
64-
}
6561
default:
6662
break
6763
}
6864
}
6965

7066
_ = context.specializeApplies(in: function, isMandatory: true)
7167

68+
removeUnusedMetatypeInstructions(in: function, context)
69+
7270
// If this is a just specialized function, try to optimize copy_addr, etc.
7371
if context.optimizeMemoryAccesses(in: function) {
7472
_ = context.eliminateDeadAllocations(in: function)
@@ -103,6 +101,15 @@ private func inlineAndDevirtualize(apply: FullApplySite, _ context: FunctionPass
103101
}
104102
}
105103

104+
private func removeUnusedMetatypeInstructions(in function: Function, _ context: FunctionPassContext) {
105+
for inst in function.instructions {
106+
if let mt = inst as? MetatypeInst,
107+
mt.isTriviallyDeadIgnoringDebugUses {
108+
context.erase(instructionIncludingDebugUses: mt)
109+
}
110+
}
111+
}
112+
106113
private func shouldInline(apply: FullApplySite, callee: Function) -> Bool {
107114
if callee.isTransparent {
108115
return true

include/swift/AST/DiagnosticEngine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,15 @@ namespace swift {
564564
/// until the next major language version.
565565
InFlightDiagnostic &warnUntilSwiftVersion(unsigned majorVersion);
566566

567+
/// Limit the diagnostic behavior to warning if the context is a
568+
/// swiftinterface.
569+
///
570+
/// This is useful for diagnostics for restrictions that may be lifted by a
571+
/// future version of the compiler. In such cases, it may be helpful to
572+
/// avoid failing to build a module from its interface if the interface was
573+
/// emitted using a compiler that no longer has the restriction.
574+
InFlightDiagnostic &warnInSwiftInterface(const DeclContext *context);
575+
567576
/// Conditionally limit the diagnostic behavior to warning until
568577
/// the specified version. If the condition is false, no limit is
569578
/// imposed, meaning (presumably) it is treated as an error.

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7053,6 +7053,10 @@ ERROR(attr_incompatible_with_back_deploy,none,
70537053
"'%0' cannot be applied to a back deployed %1",
70547054
(DeclAttribute, DescriptiveDeclKind))
70557055

7056+
ERROR(backdeployed_opaque_result_not_supported,none,
7057+
"'%0' is unsupported on a %1 with a 'some' return type",
7058+
(DeclAttribute, DescriptiveDeclKind))
7059+
70567060
//------------------------------------------------------------------------------
70577061
// MARK: Implicit opening of existential types
70587062
//------------------------------------------------------------------------------

include/swift/AST/PluginLoader.h

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,19 @@ class PluginLoader {
5252
void setRegistry(PluginRegistry *newValue);
5353
PluginRegistry *getRegistry();
5454

55-
/// Lookup a library plugin that can handle \p moduleName and return the path
56-
/// to it from `-load-plugin-library`.
57-
/// The path returned can be loaded by 'loadLibraryPlugin' method.
58-
llvm::Optional<std::string>
59-
lookupExplicitLibraryPluginByModuleName(Identifier moduleName);
60-
61-
/// Lookup a library plugin that can handle \p moduleName and return the path
62-
/// to it from `-plugin-path`.
63-
/// The path returned can be loaded by 'loadLibraryPlugin' method.
64-
llvm::Optional<std::string>
65-
lookupLibraryPluginInSearchPathByModuleName(Identifier moduleName);
66-
67-
/// Lookup an executable plugin that is declared to handle \p moduleName
68-
/// module by '-load-plugin-executable'.
69-
/// The path returned can be loaded by 'loadExecutablePlugin' method.
70-
llvm::Optional<StringRef>
71-
lookupExecutablePluginByModuleName(Identifier moduleName);
72-
73-
/// Look for dynamic libraries in paths from `-external-plugin-path` and
74-
/// return a pair of `(library path, plugin server executable)` if found.
75-
/// These paths are valid within the VFS, use `FS.getRealPath()` for their
76-
/// underlying path.
77-
llvm::Optional<std::pair<std::string, std::string>>
78-
lookupExternalLibraryPluginByModuleName(Identifier moduleName);
55+
/// Lookup a plugin that can handle \p moduleName and return the path(s) to
56+
/// it. The path returned can be loaded by 'load(Library|Executable)Plugin()'.
57+
/// The return value is a pair of a "library path" and a "executable path".
58+
///
59+
/// * (libPath: empty, execPath: empty) - plugin not found.
60+
/// * (libPath: some, execPath: empty) - load the library path by
61+
/// 'loadLibraryPlugin()'.
62+
/// * (libPath: empty, execPath: some) - load the executable path by
63+
/// 'loadExecutablePlugin()'.
64+
/// * (libPath: some, execPath: some) - load the executable path by
65+
/// 'loadExecutablePlugin()' and let the plugin load the libPath via IPC.
66+
std::pair<std::string, std::string>
67+
lookupPluginByModuleName(Identifier moduleName);
7968

8069
/// Load the specified dylib plugin path resolving the path with the
8170
/// current VFS. If it fails to load the plugin, a diagnostic is emitted, and

include/swift/AST/SearchPathOptions.h

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

1616
#include "swift/Basic/ArrayRefView.h"
1717
#include "swift/Basic/PathRemapper.h"
18+
#include "swift/Basic/TaggedUnion.h"
1819
#include "llvm/ADT/Hashing.h"
1920
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2021
#include "llvm/ADT/StringMap.h"
@@ -34,7 +35,6 @@ enum class ModuleSearchPathKind {
3435
Framework,
3536
DarwinImplicitFramework,
3637
RuntimeLibrary,
37-
CompilerPlugin,
3838
};
3939

4040
/// A single module search path that can come from different sources, e.g.
@@ -187,6 +187,26 @@ struct ExternalPluginSearchPathAndServerPath {
187187
std::string ServerPath;
188188
};
189189

190+
namespace PluginSearchOption {
191+
struct LoadPluginLibrary {
192+
std::string LibraryPath;
193+
};
194+
struct LoadPluginExecutable {
195+
std::string ExecutablePath;
196+
std::vector<std::string> ModuleNames;
197+
};
198+
struct PluginPath {
199+
std::string SearchPath;
200+
};
201+
struct ExternalPluginPath {
202+
std::string SearchPath;
203+
std::string ServerPath;
204+
};
205+
206+
using Value = TaggedUnion<LoadPluginLibrary, LoadPluginExecutable, PluginPath,
207+
ExternalPluginPath>;
208+
} // namespace PluginSearchOption
209+
190210
/// Options for controlling search path behavior.
191211
class SearchPathOptions {
192212
/// To call \c addImportSearchPath and \c addFrameworkSearchPath from
@@ -259,14 +279,6 @@ class SearchPathOptions {
259279
ImportSearchPaths.size() - 1);
260280
}
261281

262-
void addCompilerPluginLibraryPath(StringRef Path, llvm::vfs::FileSystem *FS) {
263-
CompilerPluginLibraryPaths.push_back(Path.str());
264-
Lookup.searchPathAdded(FS, CompilerPluginLibraryPaths.back(),
265-
ModuleSearchPathKind::CompilerPlugin,
266-
/*isSystem=*/false,
267-
CompilerPluginLibraryPaths.size() - 1);
268-
}
269-
270282
/// Add a single framework search path. Must only be called from
271283
/// \c ASTContext::addSearchPath.
272284
void addFrameworkSearchPath(FrameworkSearchPath NewPath,
@@ -355,27 +367,6 @@ class SearchPathOptions {
355367
Lookup.searchPathsDidChange();
356368
}
357369

358-
void setCompilerPluginLibraryPaths(
359-
std::vector<std::string> NewCompilerPluginLibraryPaths) {
360-
CompilerPluginLibraryPaths = NewCompilerPluginLibraryPaths;
361-
Lookup.searchPathsDidChange();
362-
}
363-
364-
ArrayRef<std::string> getCompilerPluginLibraryPaths() const {
365-
return CompilerPluginLibraryPaths;
366-
}
367-
368-
void setCompilerPluginExecutablePaths(
369-
std::vector<PluginExecutablePathAndModuleNames> &&newValue) {
370-
CompilerPluginExecutablePaths = std::move(newValue);
371-
Lookup.searchPathsDidChange();
372-
}
373-
374-
ArrayRef<PluginExecutablePathAndModuleNames>
375-
getCompilerPluginExecutablePaths() const {
376-
return CompilerPluginExecutablePaths;
377-
}
378-
379370
/// Path(s) to virtual filesystem overlay YAML files.
380371
std::vector<std::string> VFSOverlayFiles;
381372

@@ -391,15 +382,8 @@ class SearchPathOptions {
391382
/// preference.
392383
std::vector<std::string> RuntimeLibraryPaths;
393384

394-
/// Paths that contain compiler plugins loaded on demand for, e.g.,
395-
/// macro implementations.
396-
std::vector<std::string> PluginSearchPaths;
397-
398-
/// Pairs of external compiler plugin search paths and the corresponding
399-
/// plugin server executables.
400-
/// e.g. {"/path/to/usr/lib/swift/host/plugins",
401-
/// "/path/to/usr/bin/plugin-server"}
402-
std::vector<ExternalPluginSearchPathAndServerPath> ExternalPluginSearchPaths;
385+
/// Plugin search path options.
386+
std::vector<PluginSearchOption::Value> PluginSearchOpts;
403387

404388
/// Don't look in for compiler-provided modules.
405389
bool SkipRuntimeLibraryImportPaths = false;

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ class CompilerInvocation {
198198
SearchPathOpts.VFSOverlayFiles = Overlays;
199199
}
200200

201-
void setCompilerPluginLibraryPaths(const std::vector<std::string> &Paths) {
202-
SearchPathOpts.setCompilerPluginLibraryPaths(Paths);
203-
}
204-
205-
ArrayRef<std::string> getCompilerPluginLibraryPaths() {
206-
return SearchPathOpts.getCompilerPluginLibraryPaths();
207-
}
208-
209201
void setExtraClangArgs(const std::vector<std::string> &Args) {
210202
ClangImporterOpts.ExtraArgs = Args;
211203
}

include/swift/Option/Options.td

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,6 @@ def I : JoinedOrSeparate<["-"], "I">,
304304
def I_EQ : Joined<["-"], "I=">, Flags<[FrontendOption, ArgumentIsPath]>,
305305
Alias<I>;
306306

307-
def plugin_path : Separate<["-"], "plugin-path">,
308-
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
309-
HelpText<"Add directory to the plugin search path">;
310-
311-
def external_plugin_path : Separate<["-"], "external-plugin-path">,
312-
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
313-
HelpText<"Add directory to the plugin search path with a plugin server executable">,
314-
MetaVarName<"<path>#<plugin-server-path>">;
315-
316307
def import_underlying_module : Flag<["-"], "import-underlying-module">,
317308
Flags<[FrontendOption, NoInteractiveOption]>,
318309
HelpText<"Implicitly imports the Objective-C half of a module">;
@@ -1852,15 +1843,27 @@ def clang_include_tree_root: Separate<["-"], "clang-include-tree-root">,
18521843
Flags<[FrontendOption, NoDriverOption]>,
18531844
HelpText<"Clang Include Tree CASID">, MetaVarName<"<cas-id>">;
18541845

1846+
1847+
def plugin_search_Group : OptionGroup<"<plugin search options>">;
1848+
1849+
def plugin_path : Separate<["-"], "plugin-path">, Group<plugin_search_Group>,
1850+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
1851+
HelpText<"Add directory to the plugin search path">;
1852+
1853+
def external_plugin_path : Separate<["-"], "external-plugin-path">, Group<plugin_search_Group>,
1854+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
1855+
HelpText<"Add directory to the plugin search path with a plugin server executable">,
1856+
MetaVarName<"<path>#<plugin-server-path>">;
1857+
18551858
def load_plugin_library:
1856-
Separate<["-"], "load-plugin-library">,
1859+
Separate<["-"], "load-plugin-library">, Group<plugin_search_Group>,
18571860
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
18581861
HelpText<"Path to a dynamic library containing compiler plugins such as "
18591862
"macros">,
18601863
MetaVarName<"<path>">;
18611864

18621865
def load_plugin_executable:
1863-
Separate<["-"], "load-plugin-executable">,
1866+
Separate<["-"], "load-plugin-executable">, Group<plugin_search_Group>,
18641867
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
18651868
HelpText<"Path to an executable compiler plugins and providing module names "
18661869
"such as macros">,

include/swift/SIL/AbstractionPatternGenerators.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ class TupleElementGenerator {
291291
}
292292
}
293293

294+
/// Like `getSubstTypes`, but uses a different and possibly
295+
/// non-canonical tuple type.
296+
TupleEltTypeArrayRef getSubstTypes(Type ncSubstType) const {
297+
assert(!isFinished());
298+
if (!origTupleVanishes) {
299+
return ncSubstType->castTo<TupleType>()
300+
->getElementTypes().slice(substEltIndex,
301+
numSubstEltsForOrigElt);
302+
} else if (numSubstEltsForOrigElt == 0) {
303+
return TupleEltTypeArrayRef();
304+
} else {
305+
scratchSubstElt = TupleTypeElt(ncSubstType);
306+
return TupleEltTypeArrayRef(scratchSubstElt);
307+
}
308+
}
309+
294310
/// Call this to finalize the traversal and assert that it was done
295311
/// properly.
296312
void finish() {

include/swift/SIL/GenericSpecializationMangler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class GenericSpecializationMangler : public SpecializationMangler {
8888
: SpecializationMangler(SpecializationPass::GenericSpecializer,
8989
Serialized, F) {}
9090

91-
std::string mangleNotReabstracted(SubstitutionMap subs);
91+
std::string mangleNotReabstracted(SubstitutionMap subs,
92+
bool metatyeParamsRemoved);
9293

9394
/// Mangle a generic specialization with re-abstracted parameters.
9495
///

include/swift/SILOptimizer/Utils/Generics.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ class ReabstractionInfo {
157157
LoadableAndTrivial
158158
};
159159

160-
unsigned param2ArgIndex(unsigned ParamIdx) const {
161-
return ParamIdx + NumFormalIndirectResults;
162-
}
163-
164160
// Create a new substituted type with the updated signature.
165161
CanSILFunctionType createSubstitutedType(SILFunction *OrigF,
166162
SubstitutionMap SubstMap,
@@ -199,8 +195,8 @@ class ReabstractionInfo {
199195
ApplySite Apply, SILFunction *Callee,
200196
SubstitutionMap ParamSubs,
201197
IsSerialized_t Serialized,
202-
bool ConvertIndirectToDirect = true,
203-
bool dropMetatypeArgs = false,
198+
bool ConvertIndirectToDirect,
199+
bool dropMetatypeArgs,
204200
OptRemark::Emitter *ORE = nullptr);
205201

206202
/// Constructs the ReabstractionInfo for generic function \p Callee with
@@ -214,7 +210,11 @@ class ReabstractionInfo {
214210
IsSerialized_t isSerialized() const {
215211
return Serialized;
216212
}
217-
213+
214+
unsigned param2ArgIndex(unsigned ParamIdx) const {
215+
return ParamIdx + NumFormalIndirectResults;
216+
}
217+
218218
/// Returns true if the specialized function needs an alternative mangling.
219219
/// See hasConvertedResilientParams.
220220
bool needAlternativeMangling() const {
@@ -314,6 +314,8 @@ class ReabstractionInfo {
314314
CanSILFunctionType createSpecializedType(CanSILFunctionType SubstFTy,
315315
SILModule &M) const;
316316

317+
CanSILFunctionType createThunkType(PartialApplyInst *forPAI) const;
318+
317319
SILFunction *getNonSpecializedFunction() const { return Callee; }
318320

319321
/// Map type into a context of the specialized function.

0 commit comments

Comments
 (0)